home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 10 / develop Issue 10 code / Picture Utilities.sea / Picture Utilities / Octree Source / octree.c
MacBinary  |  1992-04-08  |  27.5 KB  |  [TEXT/KAHL]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: MacBinary (archive/macBinary).

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
1% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Wed Apr 8 18:02:31 1992, modified Wed Apr 8 18:02:31 1992, creator Think C, type ASCII, 27088 bytes "octree.c" magic text fragment for file(1) cmd, 1st line "#include <MacHeaders>", 2nd line "#include <PictUtil.h>", 3rd line "", 4th line "", 5th line "", at 0x6a50 782 bytes resource magic text fragment for file(1) cmd, 1st line "#include <MacHeaders>", 2nd line "#include <PictUtil.h>", 3rd line "", 4th line "", 5th line "" default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% dearkID deark: macbinary default
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[KAHL]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 08 6f 63 74 72 65 65 | 2e 63 00 00 00 00 00 00 |..octree|.c......|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 4b 41 48 | 4c 01 00 00 00 00 00 00 |.TEXTKAH|L.......|
|00000050| 00 00 00 00 00 69 d0 00 | 00 03 0e a6 09 1d f7 a6 |.....i..|........|
|00000060| 09 1d f7 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 58 2b 00 00 |........|....X+..|
|00000080| 23 69 6e 63 6c 75 64 65 | 20 3c 4d 61 63 48 65 61 |#include| <MacHea|
|00000090| 64 65 72 73 3e 0d 23 69 | 6e 63 6c 75 64 65 20 3c |ders>.#i|nclude <|
|000000a0| 50 69 63 74 55 74 69 6c | 2e 68 3e 0d 0d 0d 0d 2f |PictUtil|.h>..../|
|000000b0| 2a 09 63 6f 6d 70 69 6c | 65 2d 74 69 6d 65 20 73 |*.compil|e-time s|
|000000c0| 77 69 74 63 68 65 73 2e | 20 64 75 72 69 6e 67 20 |witches.| during |
|000000d0| 74 68 65 20 63 6f 75 72 | 73 65 20 6f 66 20 64 65 |the cour|se of de|
|000000e0| 76 65 6c 6f 70 69 6e 67 | 20 74 68 69 73 20 63 75 |veloping| this cu|
|000000f0| 73 74 6f 6d 20 73 61 6d | 70 6c 69 6e 67 20 6d 65 |stom sam|pling me|
|00000100| 74 68 6f 64 2c 20 77 65 | 20 66 6f 75 6e 64 20 69 |thod, we| found i|
|00000110| 74 20 75 73 65 66 75 6c | 20 74 6f 20 68 61 76 65 |t useful| to have|
|00000120| 20 61 0d 09 62 75 6e 63 | 68 20 6f 66 20 64 65 62 | a..bunc|h of deb|
|00000130| 75 67 67 69 6e 67 20 63 | 6f 64 65 20 74 68 61 74 |ugging c|ode that|
|00000140| 20 63 68 65 63 6b 73 20 | 66 6f 72 20 69 6e 76 61 | checks |for inva|
|00000150| 6c 69 64 20 64 61 74 61 | 20 73 74 72 75 63 74 75 |lid data| structu|
|00000160| 72 65 73 20 63 6f 6d 70 | 69 6c 65 64 20 69 6e 74 |res comp|iled int|
|00000170| 6f 20 73 74 72 61 74 65 | 67 69 63 20 73 70 6f 74 |o strate|gic spot|
|00000180| 73 20 69 6e 20 74 68 65 | 20 63 6f 64 65 2e 20 68 |s in the| code. h|
|00000190| 6f 77 65 76 65 72 2c 0d | 09 73 69 6e 63 65 20 74 |owever,.|.since t|
|000001a0| 68 65 20 64 65 62 75 67 | 67 69 6e 67 20 63 6f 64 |he debug|ging cod|
|000001b0| 65 20 73 6c 6f 77 73 20 | 74 68 65 20 6d 65 74 68 |e slows |the meth|
|000001c0| 6f 64 20 64 6f 77 6e 20 | 62 79 20 73 65 76 65 72 |od down |by sever|
|000001d0| 61 6c 20 6f 72 64 65 72 | 73 20 6f 66 20 6d 61 67 |al order|s of mag|
|000001e0| 6e 69 74 75 64 65 2c 20 | 77 65 20 6d 61 64 65 20 |nitude, |we made |
|000001f0| 61 6c 6c 20 6f 66 20 69 | 74 20 63 6f 6e 64 69 74 |all of i|t condit|
|00000200| 69 6f 6e 61 6c 20 6f 6e | 0d 09 74 68 65 20 66 6f |ional on|..the fo|
|00000210| 6c 6c 6f 77 69 6e 67 20 | d2 64 65 62 75 67 67 69 |llowing |.debuggi|
|00000220| 6e 67 d3 20 66 6c 61 67 | 2e 20 73 69 6d 70 6c 79 |ng. flag|. simply|
|00000230| 20 63 68 61 6e 67 65 20 | 74 68 65 20 75 6e 64 65 | change |the unde|
|00000240| 66 20 74 6f 20 61 20 64 | 65 66 69 6e 65 20 61 6e |f to a d|efine an|
|00000250| 64 20 74 68 65 6e 20 61 | 6c 6c 20 74 68 65 20 64 |d then a|ll the d|
|00000260| 65 62 75 67 67 69 6e 67 | 20 63 6f 64 65 20 77 69 |ebugging| code wi|
|00000270| 6c 6c 20 62 65 20 63 6f | 6d 70 69 6c 65 64 0d 09 |ll be co|mpiled..|
|00000280| 69 6e 20 74 6f 20 61 6c | 6c 6f 77 20 79 6f 75 20 |in to al|low you |
|00000290| 74 6f 20 74 65 73 74 20 | 79 6f 75 72 20 63 68 61 |to test |your cha|
|000002a0| 6e 67 65 73 2e 20 2a 2f | 0d 0d 23 75 6e 64 65 66 |nges. */|..#undef|
|000002b0| 20 64 65 62 75 67 67 69 | 6e 67 0d 0d 0d 0d 2f 2a | debuggi|ng..../*|
|000002c0| 20 63 6f 6e 73 74 61 6e | 74 73 20 74 68 61 74 20 | constan|ts that |
|000002d0| 77 65 20 75 73 65 20 74 | 68 72 6f 75 67 68 6f 75 |we use t|hroughou|
|000002e0| 74 20 74 68 65 20 63 6f | 64 65 20 2a 2f 0d 0d 23 |t the co|de */..#|
|000002f0| 64 65 66 69 6e 65 09 65 | 6d 70 74 79 4e 6f 64 65 |define.e|mptyNode|
|00000300| 09 09 30 78 38 30 30 30 | 09 09 2f 2a 20 74 68 69 |..0x8000|../* thi|
|00000310| 73 20 69 6e 64 69 63 61 | 74 65 73 20 74 68 61 74 |s indica|tes that|
|00000320| 20 65 69 74 68 65 72 20 | 61 20 63 68 69 6c 64 20 | either |a child |
|00000330| 6f 72 20 61 20 70 61 72 | 65 6e 74 20 73 6c 6f 74 |or a par|ent slot|
|00000340| 20 64 6f 65 73 6e d5 74 | 20 70 6f 69 6e 74 20 74 | doesn.t| point t|
|00000350| 6f 20 61 6e 79 20 6e 6f | 64 65 20 2a 2f 0d 23 64 |o any no|de */.#d|
|00000360| 65 66 69 6e 65 09 6f 62 | 73 6f 6c 65 74 65 4e 6f |efine.ob|soleteNo|
|00000370| 64 65 09 09 30 78 46 46 | 46 46 09 09 2f 2a 20 74 |de..0xFF|FF../* t|
|00000380| 68 69 73 20 76 61 6c 75 | 65 20 73 74 6f 72 65 64 |his valu|e stored|
|00000390| 20 69 6e 20 74 68 65 20 | d2 63 68 69 6c 64 72 65 | in the |.childre|
|000003a0| 6e d3 20 66 69 65 6c 64 | 20 6f 66 20 61 20 6e 6f |n. field| of a no|
|000003b0| 64 65 2c 20 69 6e 64 69 | 63 61 74 65 73 20 74 68 |de, indi|cates th|
|000003c0| 61 74 20 69 74 20 6e 65 | 65 64 73 20 74 6f 20 62 |at it ne|eds to b|
|000003d0| 65 20 72 65 6d 6f 76 65 | 64 20 2a 2f 0d 23 64 65 |e remove|d */.#de|
|000003e0| 66 69 6e 65 09 6d 61 78 | 69 6d 75 6d 4c 65 76 65 |fine.max|imumLeve|
|000003f0| 6c 09 09 38 09 09 09 2f | 2a 20 74 68 69 73 20 69 |l..8.../|* this i|
|00000400| 73 20 74 68 65 20 6d 61 | 78 69 6d 75 6d 20 6e 75 |s the ma|ximum nu|
|00000410| 6d 62 65 72 20 6f 66 20 | 6c 65 76 65 6c 73 20 74 |mber of |levels t|
|00000420| 68 61 74 20 74 68 65 20 | 6f 63 74 72 65 65 20 63 |hat the |octree c|
|00000430| 6f 76 65 72 73 20 2a 2f | 0d 0d 0d 0d 2f 2a 20 6d |overs */|..../* m|
|00000440| 61 63 72 6f 73 20 75 73 | 65 64 20 66 6f 72 20 63 |acros us|ed for c|
|00000450| 6f 6e 64 69 74 69 6f 6e | 61 6c 6c 79 20 63 6f 6d |ondition|ally com|
|00000460| 70 69 6c 69 6e 67 20 64 | 65 62 75 67 67 69 6e 67 |piling d|ebugging|
|00000470| 20 63 6f 64 65 20 2a 2f | 0d 0d 23 69 66 64 65 66 | code */|..#ifdef|
|00000480| 20 64 65 62 75 67 67 69 | 6e 67 0d 09 23 64 65 66 | debuggi|ng..#def|
|00000490| 69 6e 65 09 49 66 44 65 | 62 75 67 28 78 2c 20 79 |ine.IfDe|bug(x, y|
|000004a0| 29 09 09 7b 20 69 66 28 | 78 29 20 44 65 62 75 67 |)..{ if(|x) Debug|
|000004b0| 53 74 72 28 79 29 3b 20 | 7d 0d 09 23 64 65 66 69 |Str(y); |}..#defi|
|000004c0| 6e 65 09 56 61 6c 69 64 | 61 74 65 54 72 65 65 28 |ne.Valid|ateTree(|
|000004d0| 78 29 09 09 56 61 6c 69 | 64 61 74 65 4f 63 74 72 |x)..Vali|dateOctr|
|000004e0| 65 65 28 78 29 0d 23 65 | 6c 73 65 0d 09 23 64 65 |ee(x).#e|lse..#de|
|000004f0| 66 69 6e 65 09 49 66 44 | 65 62 75 67 28 78 2c 20 |fine.IfD|ebug(x, |
|00000500| 79 29 0d 09 23 64 65 66 | 69 6e 65 09 56 61 6c 69 |y)..#def|ine.Vali|
|00000510| 64 61 74 65 54 72 65 65 | 28 78 29 0d 23 65 6e 64 |dateTree|(x).#end|
|00000520| 69 66 0d 0d 0d 0d 2f 2a | 20 74 68 65 20 64 61 74 |if..../*| the dat|
|00000530| 61 20 73 74 72 75 63 74 | 75 72 65 73 20 75 73 65 |a struct|ures use|
|00000540| 64 20 62 79 20 74 68 69 | 73 20 73 61 6d 70 6c 69 |d by thi|s sampli|
|00000550| 6e 67 20 6d 65 74 68 6f | 64 20 2a 2f 0d 0d 74 79 |ng metho|d */..ty|
|00000560| 70 65 64 65 66 20 73 74 | 72 75 63 74 20 6f 63 74 |pedef st|ruct oct|
|00000570| 72 65 65 4e 6f 64 65 20 | 7b 0d 09 73 68 6f 72 74 |reeNode |{..short|
|00000580| 09 63 68 69 6c 64 72 65 | 6e 3b 09 09 09 2f 2a 20 |.childre|n;.../* |
|00000590| 63 6f 75 6e 74 20 6f 66 | 20 68 6f 77 20 6d 61 6e |count of| how man|
|000005a0| 79 20 6c 65 61 76 65 73 | 20 61 72 65 20 66 69 6c |y leaves| are fil|
|000005b0| 6c 65 64 20 2a 2f 0d 09 | 73 68 6f 72 74 09 70 61 |led */..|short.pa|
|000005c0| 72 65 6e 74 3b 0d 09 73 | 68 6f 72 74 09 6c 65 61 |rent;..s|hort.lea|
|000005d0| 66 5b 38 5d 3b 0d 7d 20 | 6f 63 74 72 65 65 4e 6f |f[8];.} |octreeNo|
|000005e0| 64 65 3b 0d 0d 74 79 70 | 65 64 65 66 20 73 74 72 |de;..typ|edef str|
|000005f0| 75 63 74 20 6f 63 74 72 | 65 65 43 6f 6c 6f 72 20 |uct octr|eeColor |
|00000600| 7b 0d 09 6c 6f 6e 67 09 | 09 09 63 6f 75 6e 74 3b |{..long.|..count;|
|00000610| 0d 09 75 6e 73 69 67 6e | 65 64 20 6c 6f 6e 67 09 |..unsign|ed long.|
|00000620| 74 6f 74 61 6c 52 65 64 | 3b 09 09 2f 2a 20 74 68 |totalRed|;../* th|
|00000630| 69 73 20 74 6f 74 61 6c | 20 61 6c 6c 6f 77 73 20 |is total| allows |
|00000640| 75 73 20 74 6f 20 61 76 | 65 72 61 67 65 20 61 6c |us to av|erage al|
|00000650| 6c 20 74 68 65 20 63 6f | 6d 70 6f 6e 65 6e 74 73 |l the co|mponents|
|00000660| 20 6f 66 20 74 68 69 73 | 20 65 6e 74 72 79 20 2a | of this| entry *|
|00000670| 2f 0d 09 75 6e 73 69 67 | 6e 65 64 20 6c 6f 6e 67 |/..unsig|ned long|
|00000680| 09 74 6f 74 61 6c 47 72 | 65 65 6e 3b 0d 09 75 6e |.totalGr|een;..un|
|00000690| 73 69 67 6e 65 64 20 6c | 6f 6e 67 09 74 6f 74 61 |signed l|ong.tota|
|000006a0| 6c 42 6c 75 65 3b 0d 09 | 73 68 6f 72 74 09 09 6c |lBlue;..|short..l|
|000006b0| 65 76 65 6c 3b 0d 09 73 | 68 6f 72 74 09 09 6e 65 |evel;..s|hort..ne|
|000006c0| 78 74 3b 09 09 2f 2a 20 | 63 6f 6c 6f 72 20 69 6e |xt;../* |color in|
|000006d0| 64 65 78 20 6f 66 20 74 | 68 65 20 6e 65 78 74 20 |dex of t|he next |
|000006e0| 63 6f 6c 6f 72 20 61 74 | 20 74 68 69 73 20 6c 65 |color at| this le|
|000006f0| 76 65 6c 20 2a 2f 0d 09 | 73 68 6f 72 74 09 09 70 |vel */..|short..p|
|00000700| 61 72 65 6e 74 3b 09 09 | 2f 2a 20 6e 6f 64 65 20 |arent;..|/* node |
|00000710| 69 6e 64 65 78 20 6f 66 | 20 74 68 65 20 6e 6f 64 |index of| the nod|
|00000720| 65 20 74 68 61 74 20 6f | 77 6e 73 20 74 68 69 73 |e that o|wns this|
|00000730| 20 63 6f 6c 6f 72 20 2a | 2f 0d 09 73 68 6f 72 74 | color *|/..short|
|00000740| 09 09 70 61 64 64 69 6e | 67 3b 09 09 2f 2a 20 74 |..paddin|g;../* t|
|00000750| 6f 20 6d 61 6b 65 20 74 | 68 65 20 73 74 72 75 63 |o make t|he struc|
|00000760| 74 75 72 65 20 6c 6f 6e | 67 20 61 6c 69 67 6e 65 |ture lon|g aligne|
|00000770| 64 20 2a 2f 0d 7d 20 6f | 63 74 72 65 65 43 6f 6c |d */.} o|ctreeCol|
|00000780| 6f 72 3b 0d 0d 74 79 70 | 65 64 65 66 20 73 74 72 |or;..typ|edef str|
|00000790| 75 63 74 20 6f 63 74 72 | 65 65 20 7b 0d 09 73 68 |uct octr|ee {..sh|
|000007a0| 6f 72 74 09 09 6d 61 78 | 69 6d 75 6d 4e 6f 64 65 |ort..max|imumNode|
|000007b0| 73 3b 0d 09 73 68 6f 72 | 74 09 09 6e 6f 64 65 73 |s;..shor|t..nodes|
|000007c0| 3b 0d 09 6f 63 74 72 65 | 65 4e 6f 64 65 09 2a 6e |;..octre|eNode.*n|
|000007d0| 6f 64 65 42 61 73 65 3b | 0d 09 73 68 6f 72 74 09 |odeBase;|..short.|
|000007e0| 09 6d 61 78 69 6d 75 6d | 43 6f 6c 6f 72 73 3b 0d |.maximum|Colors;.|
|000007f0| 09 73 68 6f 72 74 09 09 | 63 6f 6c 6f 72 73 3b 0d |.short..|colors;.|
|00000800| 09 6f 63 74 72 65 65 43 | 6f 6c 6f 72 09 2a 63 6f |.octreeC|olor.*co|
|00000810| 6c 6f 72 42 61 73 65 3b | 0d 09 73 68 6f 72 74 09 |lorBase;|..short.|
|00000820| 09 76 61 6c 69 64 61 74 | 69 6f 6e 43 6f 75 6e 74 |.validat|ionCount|
|00000830| 3b 0d 09 73 68 6f 72 74 | 09 09 63 6f 6c 6f 72 4c |;..short|..colorL|
|00000840| 69 73 74 5b 6d 61 78 69 | 6d 75 6d 4c 65 76 65 6c |ist[maxi|mumLevel|
|00000850| 20 2b 20 31 5d 3b 09 2f | 2a 20 74 68 65 73 65 20 | + 1];./|* these |
|00000860| 61 72 65 20 69 6e 64 65 | 78 65 73 20 69 6e 74 6f |are inde|xes into|
|00000870| 20 74 68 65 20 66 69 72 | 73 74 20 63 6f 6c 6f 72 | the fir|st color|
|00000880| 20 65 6e 74 72 79 20 61 | 74 20 74 68 69 73 20 6c | entry a|t this l|
|00000890| 65 76 65 6c 20 28 7a 65 | 72 6f 20 69 73 20 61 6c |evel (ze|ro is al|
|000008a0| 6c 6f 63 61 74 65 64 2c | 20 62 75 74 20 75 6e 75 |located,| but unu|
|000008b0| 73 65 64 29 2a 2f 0d 7d | 20 6f 63 74 72 65 65 3b |sed)*/.}| octree;|
|000008c0| 0d 0d 0d 2f 2a 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |.../*---|--------|
|000008d0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000008e0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000008f0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000900| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000910| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00000920| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2a 2f 0d 2f |--------|----*/./|
|00000930| 2a 09 74 68 69 73 20 69 | 73 20 74 68 65 20 63 6f |*.this i|s the co|
|00000940| 64 65 20 66 6f 72 20 61 | 20 63 75 73 74 6f 6d 20 |de for a| custom |
|00000950| 63 6f 6c 6f 72 20 73 61 | 6d 70 6c 69 6e 67 20 6d |color sa|mpling m|
|00000960| 65 74 68 6f 64 20 74 68 | 61 74 20 63 61 6e 20 62 |ethod th|at can b|
|00000970| 65 20 63 61 6c 6c 65 64 | 20 62 79 20 70 69 63 74 |e called| by pict|
|00000980| 75 72 65 20 75 74 69 6c | 69 74 69 65 73 20 74 6f |ure util|ities to|
|00000990| 20 64 65 74 65 72 6d 69 | 6e 65 20 74 68 65 20 62 | determi|ne the b|
|000009a0| 65 73 74 0d 09 73 65 74 | 20 6f 66 20 63 6f 6c 6f |est..set| of colo|
|000009b0| 72 73 20 74 6f 20 75 73 | 65 20 66 6f 72 20 61 20 |rs to us|e for a |
|000009c0| 70 69 63 74 75 72 65 2e | 20 69 74 20 75 73 65 73 |picture.| it uses|
|000009d0| 20 61 20 64 61 74 61 20 | 73 74 72 75 63 74 75 72 | a data |structur|
|000009e0| 65 20 6b 6e 6f 77 6e 20 | 61 73 20 61 6e 20 6f 63 |e known |as an oc|
|000009f0| 74 72 65 65 20 74 6f 20 | 6b 65 65 70 20 74 72 61 |tree to |keep tra|
|00000a00| 63 6b 20 6f 66 20 69 74 | 73 20 63 6f 6c 6f 72 73 |ck of it|s colors|
|00000a10| 20 66 6f 6c 6c 6f 77 69 | 6e 67 0d 09 61 20 6d 65 | followi|ng..a me|
|00000a20| 74 68 6f 64 20 6c 6f 6f | 73 65 6c 79 20 64 65 73 |thod loo|sely des|
|00000a30| 63 72 69 62 65 64 20 69 | 6e 20 47 72 61 70 68 69 |cribed i|n Graphi|
|00000a40| 63 73 20 47 65 6d 73 20 | 6f 6e 20 70 61 67 65 20 |cs Gems |on page |
|00000a50| 32 38 37 20 62 79 20 4d | 69 63 68 61 65 6c 20 47 |287 by M|ichael G|
|00000a60| 65 72 76 61 75 74 7a 20 | 61 6e 64 20 57 65 72 6e |ervautz |and Wern|
|00000a70| 65 72 20 50 75 72 67 61 | 74 68 6f 66 65 72 2e 0d |er Purga|thofer..|
|00000a80| 0d 09 70 69 63 74 75 72 | 65 20 75 74 69 6c 69 74 |..pictur|e utilit|
|00000a90| 69 65 73 20 77 69 6c 6c | 20 73 74 6f 72 65 20 6f |ies will| store o|
|00000aa0| 6e 65 20 6c 6f 6e 67 20 | 77 6f 72 64 20 66 6f 72 |ne long |word for|
|00000ab0| 20 75 73 20 61 6e 64 20 | 70 61 73 73 20 69 74 20 | us and |pass it |
|00000ac0| 74 6f 20 65 61 63 68 20 | 6f 66 20 6f 75 72 20 72 |to each |of our r|
|00000ad0| 6f 75 74 69 6e 65 73 2c | 20 73 6f 20 77 65 20 75 |outines,| so we u|
|00000ae0| 73 65 20 74 68 69 73 20 | 74 6f 20 73 74 6f 72 65 |se this |to store|
|00000af0| 20 61 20 68 61 6e 64 6c | 65 0d 09 74 6f 20 6f 75 | a handl|e..to ou|
|00000b00| 72 20 6d 61 69 6e 20 6f | 63 74 72 65 65 20 73 74 |r main o|ctree st|
|00000b10| 72 75 63 74 75 72 65 2e | 20 77 65 20 6c 6f 63 6b |ructure.| we lock|
|00000b20| 20 61 6e 64 20 64 65 72 | 65 66 65 72 65 6e 63 65 | and der|eference|
|00000b30| 20 74 68 69 73 20 68 61 | 6e 64 6c 65 20 75 70 6f | this ha|ndle upo|
|00000b40| 6e 20 65 6e 74 65 72 69 | 6e 67 20 65 61 63 68 20 |n enteri|ng each |
|00000b50| 6f 66 20 74 68 65 20 d2 | 70 75 62 6c 69 63 d3 20 |of the .|public. |
|00000b60| 72 6f 75 74 69 6e 65 73 | 20 74 68 61 74 0d 09 70 |routines| that..p|
|00000b70| 69 63 74 75 72 65 20 75 | 74 69 6c 69 74 69 65 73 |icture u|tilities|
|00000b80| 20 63 61 6c 6c 73 20 61 | 6e 64 20 77 65 20 75 6e | calls a|nd we un|
|00000b90| 6c 6f 63 6b 20 69 74 20 | 75 70 6f 6e 20 65 78 69 |lock it |upon exi|
|00000ba0| 74 69 6e 67 20 74 68 65 | 73 65 20 72 6f 75 74 69 |ting the|se routi|
|00000bb0| 6e 65 73 2e 20 6e 6f 74 | 65 20 74 68 61 74 20 73 |nes. not|e that s|
|00000bc0| 69 6e 63 65 20 77 65 20 | 64 6f 6e d5 74 20 61 6c |ince we |don.t al|
|00000bd0| 6c 6f 63 61 74 65 20 6d | 65 6d 6f 72 79 20 69 6e |locate m|emory in|
|00000be0| 20 61 6e 79 0d 09 6f 66 | 20 74 68 65 20 69 6e 74 | any..of| the int|
|00000bf0| 65 72 6e 61 6c 20 6f 63 | 74 72 65 65 20 72 6f 75 |ernal oc|tree rou|
|00000c00| 74 69 6e 65 73 2c 20 77 | 65 20 77 6f 75 6c 64 6e |tines, w|e wouldn|
|00000c10| d5 74 20 72 65 61 6c 6c | 79 20 6e 65 65 64 20 74 |.t reall|y need t|
|00000c20| 6f 20 6c 6f 63 6b 20 74 | 68 69 73 20 68 61 6e 64 |o lock t|his hand|
|00000c30| 6c 65 20 64 6f 77 6e 2c | 20 62 75 74 20 6c 6f 63 |le down,| but loc|
|00000c40| 6b 69 6e 67 20 69 74 20 | 64 6f 65 73 6e d5 74 20 |king it |doesn.t |
|00000c50| 63 6f 73 74 20 75 73 20 | 61 6e 79 0d 09 6d 65 61 |cost us |any..mea|
|00000c60| 73 75 72 61 62 6c 65 20 | 74 69 6d 65 20 61 6e 64 |surable |time and|
|00000c70| 20 61 6c 6c 6f 77 73 20 | 75 73 20 74 6f 20 63 68 | allows |us to ch|
|00000c80| 61 6e 67 65 20 74 68 65 | 20 69 6e 74 65 72 6e 61 |ange the| interna|
|00000c90| 6c 73 20 6c 61 74 65 72 | 20 74 6f 20 61 6c 6c 6f |ls later| to allo|
|00000ca0| 63 61 74 65 20 6d 65 6d | 6f 72 79 20 77 69 74 68 |cate mem|ory with|
|00000cb0| 6f 75 74 20 62 65 69 6e | 67 20 62 69 74 74 65 6e |out bein|g bitten|
|00000cc0| 20 62 79 20 61 20 6d 65 | 6d 6f 72 79 0d 09 62 75 | by a me|mory..bu|
|00000cd0| 67 2e 0d 0d 09 77 65 20 | 61 6c 73 6f 20 68 61 76 |g....we |also hav|
|00000ce0| 65 20 74 77 6f 20 6f 74 | 68 65 72 20 68 61 6e 64 |e two ot|her hand|
|00000cf0| 6c 65 73 3b 20 6f 6e 65 | 20 66 6f 72 20 74 68 65 |les; one| for the|
|00000d00| 20 6d 61 78 69 6d 75 6d | 20 6e 75 6d 62 65 72 20 | maximum| number |
|00000d10| 6f 66 20 6e 6f 64 65 73 | 20 74 68 61 74 20 77 65 |of nodes| that we|
|00000d20| 20 77 6f 75 6c 64 20 65 | 76 65 72 20 6e 65 65 64 | would e|ver need|
|00000d30| 20 74 6f 20 61 6c 6c 6f | 63 61 74 65 20 61 6e 64 | to allo|cate and|
|00000d40| 20 74 68 65 0d 09 6f 74 | 68 65 72 20 66 6f 72 20 | the..ot|her for |
|00000d50| 74 68 65 20 63 6f 6c 6f | 72 73 20 74 68 61 74 20 |the colo|rs that |
|00000d60| 77 65 20 77 69 6c 6c 20 | 72 65 74 75 72 6e 2e 20 |we will |return. |
|00000d70| 77 65 20 6e 65 65 64 20 | 6f 6e 65 20 6d 6f 72 65 |we need |one more|
|00000d80| 20 73 6c 6f 74 20 74 68 | 61 6e 20 74 68 65 20 6e | slot th|an the n|
|00000d90| 75 6d 62 65 72 20 6f 66 | 20 63 6f 6c 6f 72 73 20 |umber of| colors |
|00000da0| 72 65 71 75 65 73 74 65 | 64 2c 20 62 65 63 61 75 |requeste|d, becau|
|00000db0| 73 65 20 74 68 65 0d 09 | 61 6c 67 6f 72 69 74 68 |se the..|algorith|
|00000dc0| 6d 20 69 6e 73 65 72 74 | 73 20 65 76 65 72 79 20 |m insert|s every |
|00000dd0| 6e 65 77 20 63 6f 6c 6f | 72 20 74 68 61 74 20 69 |new colo|r that i|
|00000de0| 74 20 66 69 6e 64 73 20 | 61 6e 64 20 6f 6e 6c 79 |t finds |and only|
|00000df0| 20 74 68 65 6e 20 64 6f | 65 73 20 69 74 20 63 68 | then do|es it ch|
|00000e00| 65 63 6b 20 74 6f 20 73 | 65 65 20 69 66 20 77 65 |eck to s|ee if we|
|00000e10| 20 68 61 76 65 20 74 6f | 6f 20 6d 61 6e 79 20 63 | have to|o many c|
|00000e20| 6f 6c 6f 72 73 20 61 6e | 64 0d 09 77 65 20 6e 65 |olors an|d..we ne|
|00000e30| 65 64 20 74 6f 20 72 65 | 64 75 63 65 20 74 68 65 |ed to re|duce the|
|00000e40| 20 6f 63 74 72 65 65 2e | 0d 0d 09 74 68 65 20 73 | octree.|...the s|
|00000e50| 74 61 6e 64 61 72 64 20 | 77 61 79 20 6f 66 20 77 |tandard |way of w|
|00000e60| 6f 72 6b 69 6e 67 20 77 | 69 74 68 20 6f 63 74 72 |orking w|ith octr|
|00000e70| 65 65 20 6e 6f 64 65 73 | 20 69 73 20 74 6f 20 68 |ee nodes| is to h|
|00000e80| 61 76 65 20 65 69 67 68 | 74 20 70 6f 69 6e 74 65 |ave eigh|t pointe|
|00000e90| 72 73 20 69 6e 20 65 61 | 63 68 20 6e 6f 64 65 20 |rs in ea|ch node |
|00000ea0| 74 6f 20 74 68 65 20 76 | 61 72 69 6f 75 73 20 63 |to the v|arious c|
|00000eb0| 68 69 6c 64 72 65 6e 20 | 6f 66 0d 09 74 68 61 74 |hildren |of..that|
|00000ec0| 20 6e 6f 64 65 2e 20 68 | 6f 77 65 76 65 72 2c 20 | node. h|owever, |
|00000ed0| 69 6e 20 61 6e 20 65 66 | 66 6f 72 74 20 74 6f 20 |in an ef|fort to |
|00000ee0| 72 65 64 75 63 65 20 74 | 68 65 20 73 74 6f 72 61 |reduce t|he stora|
|00000ef0| 67 65 20 72 65 71 75 69 | 72 65 6d 65 6e 74 73 20 |ge requi|rements |
|00000f00| 28 61 6e 64 20 6e 6f 74 | 20 62 75 72 64 65 6e 20 |(and not| burden |
|00000f10| 74 68 65 20 6d 65 6d 6f | 72 79 20 6d 61 6e 61 67 |the memo|ry manag|
|00000f20| 65 72 20 77 69 74 68 0d | 09 74 6f 6f 20 6d 61 6e |er with.|.too man|
|00000f30| 79 20 62 6c 6f 63 6b 73 | 29 2c 20 77 65 20 68 61 |y blocks|), we ha|
|00000f40| 76 65 20 63 68 6f 73 65 | 6e 20 74 6f 20 75 73 65 |ve chose|n to use|
|00000f50| 20 69 6e 64 69 63 65 73 | 20 69 6e 74 6f 20 74 68 | indices| into th|
|00000f60| 65 20 6e 6f 64 65 42 61 | 73 65 20 61 72 72 61 79 |e nodeBa|se array|
|00000f70| 20 66 6f 72 20 65 61 63 | 68 20 6f 66 20 74 68 65 | for eac|h of the|
|00000f80| 20 63 68 69 6c 64 72 65 | 6e 2e 20 61 20 63 68 69 | childre|n. a chi|
|00000f90| 6c 64 20 6f 66 20 61 20 | 6e 6f 64 65 0d 09 63 61 |ld of a |node..ca|
|00000fa0| 6e 20 65 69 74 68 65 72 | 20 62 65 20 61 20 63 6f |n either| be a co|
|00000fb0| 6c 6f 72 20 6f 72 20 61 | 6e 6f 74 68 65 72 20 6e |lor or a|nother n|
|00000fc0| 6f 64 65 20 61 6e 64 20 | 73 69 6e 63 65 20 74 68 |ode and |since th|
|00000fd0| 65 73 65 20 74 77 6f 20 | 74 79 70 65 73 20 6f 66 |ese two |types of|
|00000fe0| 20 6f 62 6a 65 63 74 73 | 20 61 72 65 20 64 69 66 | objects| are dif|
|00000ff0| 66 65 72 65 6e 74 20 73 | 69 7a 65 73 20 61 6e 64 |ferent s|izes and|
|00001000| 20 73 74 6f 72 65 64 20 | 69 6e 0d 09 64 69 66 66 | stored |in..diff|
|00001010| 65 72 65 6e 74 20 61 72 | 72 61 79 73 2c 20 77 65 |erent ar|rays, we|
|00001020| 20 75 73 65 20 74 68 65 | 20 63 6f 6e 76 65 6e 74 | use the| convent|
|00001030| 69 6f 6e 20 6f 66 20 6e | 65 67 61 74 69 76 65 20 |ion of n|egative |
|00001040| 6e 75 6d 62 65 72 73 20 | 74 6f 20 69 6e 64 69 63 |numbers |to indic|
|00001050| 61 74 65 20 74 68 61 74 | 20 74 68 65 20 62 69 74 |ate that| the bit|
|00001060| 77 69 73 65 20 6e 6f 74 | 20 6f 66 20 74 68 65 20 |wise not| of the |
|00001070| 63 68 69 6c 64 20 69 6e | 64 65 78 20 69 73 0d 09 |child in|dex is..|
|00001080| 61 6e 20 69 6e 64 65 78 | 20 69 6e 74 6f 20 74 68 |an index| into th|
|00001090| 65 20 63 6f 6c 6f 72 20 | 74 61 62 6c 65 20 61 6e |e color |table an|
|000010a0| 64 20 70 6f 73 69 74 69 | 76 65 20 6e 75 6d 62 65 |d positi|ve numbe|
|000010b0| 72 73 20 74 6f 20 69 6e | 64 69 63 61 74 65 20 74 |rs to in|dicate t|
|000010c0| 68 61 74 20 74 68 65 20 | 63 68 69 6c 64 20 69 6e |hat the |child in|
|000010d0| 64 65 78 20 69 73 20 61 | 6e 20 69 6e 64 65 78 20 |dex is a|n index |
|000010e0| 69 6e 74 6f 20 74 68 65 | 20 6e 6f 64 65 20 74 61 |into the| node ta|
|000010f0| 62 6c 65 2e 0d 09 74 68 | 65 72 65 20 69 73 20 61 |ble...th|ere is a|
|00001100| 6c 73 6f 20 61 20 73 70 | 65 63 69 61 6c 20 63 6f |lso a sp|ecial co|
|00001110| 6e 73 74 61 6e 74 20 28 | 65 6d 70 74 79 4e 6f 64 |nstant (|emptyNod|
|00001120| 65 29 20 74 6f 20 69 6e | 64 69 63 61 74 65 20 74 |e) to in|dicate t|
|00001130| 68 61 74 20 61 20 63 68 | 69 6c 64 20 65 6e 74 72 |hat a ch|ild entr|
|00001140| 79 20 69 73 20 65 6d 70 | 74 79 2e 0d 0d 09 65 61 |y is emp|ty....ea|
|00001150| 63 68 20 6e 6f 64 65 20 | 61 6e 64 20 63 6f 6c 6f |ch node |and colo|
|00001160| 72 20 6b 65 65 70 73 20 | 61 6e 20 69 6e 64 65 78 |r keeps |an index|
|00001170| 20 74 6f 20 69 74 73 20 | 70 61 72 65 6e 74 20 6e | to its |parent n|
|00001180| 6f 64 65 2c 20 77 68 69 | 63 68 20 67 72 65 61 74 |ode, whi|ch great|
|00001190| 6c 79 20 73 70 65 65 64 | 73 20 75 70 20 74 68 65 |ly speed|s up the|
|000011a0| 20 72 65 64 75 63 74 69 | 6f 6e 20 70 72 6f 63 65 | reducti|on proce|
|000011b0| 73 73 2e 20 6e 6f 64 65 | 73 20 61 6c 73 6f 0d 09 |ss. node|s also..|
|000011c0| 6b 65 65 70 20 61 20 63 | 6f 75 6e 74 20 6f 66 20 |keep a c|ount of |
|000011d0| 74 68 65 69 72 20 63 68 | 69 6c 64 72 65 6e 2c 20 |their ch|ildren, |
|000011e0| 61 6c 74 68 6f 75 67 68 | 20 74 68 69 73 20 69 73 |although| this is|
|000011f0| 6e d5 74 20 61 73 20 6d | 75 63 68 20 6f 66 20 61 |n.t as m|uch of a|
|00001200| 20 77 69 6e 20 66 6f 72 | 20 74 68 65 20 72 65 64 | win for| the red|
|00001210| 75 63 74 69 6f 6e 20 70 | 72 6f 63 65 73 73 2e 0d |uction p|rocess..|
|00001220| 0d 09 74 68 65 20 77 61 | 79 20 74 68 65 20 61 6c |..the wa|y the al|
|00001230| 67 6f 72 69 74 68 6d 20 | 77 6f 72 6b 73 20 69 73 |gorithm |works is|
|00001240| 20 74 68 61 74 20 66 6f | 72 20 65 76 65 72 79 20 | that fo|r every |
|00001250| 63 6f 6c 6f 72 2c 20 77 | 65 20 63 61 6c 6c 20 41 |color, w|e call A|
|00001260| 64 64 43 6f 6c 6f 72 54 | 6f 4f 63 74 72 65 65 2c |ddColorT|oOctree,|
|00001270| 20 77 68 69 63 68 20 77 | 61 6c 6b 73 20 64 6f 77 | which w|alks dow|
|00001280| 6e 20 61 6c 6c 20 74 68 | 65 20 6e 6f 64 65 73 2c |n all th|e nodes,|
|00001290| 0d 09 75 6e 74 69 6c 20 | 69 74 20 66 69 6e 64 73 |..until |it finds|
|000012a0| 20 74 68 65 20 63 6f 72 | 72 65 63 74 20 73 6c 6f | the cor|rect slo|
|000012b0| 74 20 66 6f 72 20 74 68 | 65 20 63 6f 6c 6f 72 2e |t for th|e color.|
|000012c0| 20 74 6f 20 64 65 74 65 | 72 6d 69 6e 65 20 74 68 | to dete|rmine th|
|000012d0| 65 20 63 6f 72 72 65 63 | 74 20 73 6c 6f 74 2c 20 |e correc|t slot, |
|000012e0| 77 65 20 75 73 65 20 6f | 6e 6c 79 20 74 68 65 20 |we use o|nly the |
|000012f0| 68 69 67 68 20 62 79 74 | 65 20 6f 66 20 65 61 63 |high byt|e of eac|
|00001300| 68 0d 09 63 6f 6d 70 6f | 6e 65 6e 74 2c 20 77 68 |h..compo|nent, wh|
|00001310| 69 63 68 20 77 65 20 73 | 75 63 65 73 73 69 76 65 |ich we s|ucessive|
|00001320| 6c 79 20 73 68 69 66 74 | 20 61 73 20 77 65 20 77 |ly shift| as we w|
|00001330| 61 6c 6b 20 74 68 72 6f | 75 67 68 20 74 68 65 20 |alk thro|ugh the |
|00001340| 74 72 65 65 2c 20 75 73 | 69 6e 67 20 74 68 65 20 |tree, us|ing the |
|00001350| 68 69 67 68 65 73 74 20 | 62 69 74 20 6f 66 20 65 |highest |bit of e|
|00001360| 61 63 68 20 63 6f 6d 70 | 6f 6e 65 6e 74 20 74 6f |ach comp|onent to|
|00001370| 0d 09 73 65 6c 65 63 74 | 20 77 68 69 63 68 20 63 |..select| which c|
|00001380| 68 69 6c 64 20 6f 66 20 | 74 68 65 20 6e 6f 64 65 |hild of |the node|
|00001390| 20 74 6f 20 6c 6f 6f 6b | 20 61 74 2e 20 69 66 20 | to look| at. if |
|000013a0| 74 68 65 20 63 68 69 6c | 64 20 6e 6f 64 65 20 69 |the chil|d node i|
|000013b0| 73 20 65 6d 70 74 79 20 | 61 6e 64 20 77 65 20 68 |s empty |and we h|
|000013c0| 61 76 65 6e d5 74 20 72 | 65 61 63 68 65 64 20 6f |aven.t r|eached o|
|000013d0| 75 72 20 6d 61 78 69 6d | 75 6d 20 6c 65 76 65 6c |ur maxim|um level|
|000013e0| 0d 09 79 65 74 2c 20 77 | 65 20 63 72 65 61 74 65 |..yet, w|e create|
|000013f0| 20 61 20 6e 65 77 20 6e | 6f 64 65 20 61 6e 64 20 | a new n|ode and |
|00001400| 63 6f 6e 74 69 6e 75 65 | 20 74 68 65 20 61 64 64 |continue| the add|
|00001410| 20 70 72 6f 63 65 73 73 | 2e 20 69 66 20 77 65 20 | process|. if we |
|00001420| 68 61 76 65 20 72 65 61 | 63 68 65 64 20 6f 75 72 |have rea|ched our|
|00001430| 20 6d 61 78 69 6d 75 6d | 20 6c 65 76 65 6c 2c 20 | maximum| level, |
|00001440| 74 68 65 6e 20 77 65 20 | 63 72 65 61 74 65 0d 09 |then we |create..|
|00001450| 61 20 6e 65 77 20 63 6f | 6c 6f 72 20 61 6e 64 20 |a new co|lor and |
|00001460| 73 61 76 65 20 6f 75 72 | 20 63 6f 6c 6f 72 2d 74 |save our| color-t|
|00001470| 6f 2d 61 64 64 20 74 68 | 65 72 65 2e 20 69 66 20 |o-add th|ere. if |
|00001480| 74 68 65 20 63 68 69 6c | 64 20 65 6e 74 72 79 20 |the chil|d entry |
|00001490| 70 6f 69 6e 74 73 20 74 | 6f 20 61 6e 20 61 6c 72 |points t|o an alr|
|000014a0| 65 61 64 79 20 65 78 69 | 73 74 69 6e 67 20 63 6f |eady exi|sting co|
|000014b0| 6c 6f 72 2c 20 74 68 65 | 6e 20 77 65 20 61 64 64 |lor, the|n we add|
|000014c0| 0d 09 6f 75 72 20 6e 65 | 77 20 63 6f 6c 6f 72 20 |..our ne|w color |
|000014d0| 74 6f 20 74 68 65 20 61 | 63 63 75 6d 75 6c 61 74 |to the a|ccumulat|
|000014e0| 69 6e 67 20 74 6f 74 61 | 6c 73 20 69 6e 20 74 68 |ing tota|ls in th|
|000014f0| 65 20 63 6f 6c 6f 72 20 | 65 6e 74 72 79 20 61 6e |e color |entry an|
|00001500| 64 20 72 65 74 75 72 6e | 2e 0d 0d 09 61 66 74 65 |d return|....afte|
|00001510| 72 20 61 64 64 69 6e 67 | 20 61 20 6e 65 77 20 63 |r adding| a new c|
|00001520| 6f 6c 6f 72 2c 20 77 65 | 20 63 68 65 63 6b 20 74 |olor, we| check t|
|00001530| 6f 20 73 65 65 20 69 66 | 20 74 68 65 20 6e 75 6d |o see if| the num|
|00001540| 62 65 72 20 6f 66 20 63 | 6f 6c 6f 72 73 20 69 6e |ber of c|olors in|
|00001550| 20 74 68 65 20 74 72 65 | 65 20 69 73 20 67 72 65 | the tre|e is gre|
|00001560| 61 74 65 72 20 74 68 61 | 6e 20 74 68 65 20 6e 75 |ater tha|n the nu|
|00001570| 6d 62 65 72 20 72 65 71 | 75 65 73 74 65 64 2e 0d |mber req|uested..|
|00001580| 09 69 66 20 74 68 69 73 | 20 69 73 20 74 68 65 20 |.if this| is the |
|00001590| 63 61 73 65 2c 20 74 68 | 65 6e 20 77 65 20 63 61 |case, th|en we ca|
|000015a0| 6c 6c 20 52 65 64 75 63 | 65 4f 63 74 72 65 65 2c |ll Reduc|eOctree,|
|000015b0| 20 77 68 69 63 68 20 69 | 6e 20 61 20 76 65 72 79 | which i|n a very|
|000015c0| 20 73 69 6d 70 6c 69 73 | 74 69 63 20 77 61 79 2c | simplis|tic way,|
|000015d0| 20 63 6f 6d 62 69 6e 65 | 73 20 74 77 6f 20 65 78 | combine|s two ex|
|000015e0| 69 73 74 69 6e 67 20 63 | 6f 6c 6f 72 20 65 6e 74 |isting c|olor ent|
|000015f0| 72 69 65 73 0d 09 69 6e | 74 6f 20 6f 6e 65 20 74 |ries..in|to one t|
|00001600| 68 61 74 20 73 70 61 6e | 73 20 61 20 62 72 6f 61 |hat span|s a broa|
|00001610| 64 65 72 20 73 65 63 74 | 69 6f 6e 20 6f 66 20 74 |der sect|ion of t|
|00001620| 68 65 20 52 47 42 20 63 | 75 62 65 2e 0d 0d 09 77 |he RGB c|ube....w|
|00001630| 68 65 6e 20 70 69 63 74 | 75 72 65 20 75 74 69 6c |hen pict|ure util|
|00001640| 69 74 69 65 73 20 61 73 | 6b 73 20 75 73 20 66 6f |ities as|ks us fo|
|00001650| 72 20 74 68 65 20 63 6f | 6c 6f 72 20 74 61 62 6c |r the co|lor tabl|
|00001660| 65 2c 20 77 65 20 63 61 | 6e 20 72 65 74 75 72 6e |e, we ca|n return|
|00001670| 20 69 74 20 64 69 72 65 | 63 74 6c 79 20 6f 75 74 | it dire|ctly out|
|00001680| 20 6f 66 20 6f 75 72 20 | 63 6f 6c 6f 72 42 61 73 | of our |colorBas|
|00001690| 65 20 61 72 72 61 79 2c | 20 73 69 6e 63 65 20 74 |e array,| since t|
|000016a0| 68 65 0d 09 6f 63 74 72 | 65 65 20 68 61 73 20 62 |he..octr|ee has b|
|000016b0| 65 65 6e 20 62 65 69 6e | 67 20 74 72 69 6d 6d 65 |een bein|g trimme|
|000016c0| 64 20 61 73 20 77 65 20 | 67 6f 2e 0d 0d 09 6d 75 |d as we |go....mu|
|000016d0| 63 68 20 6f 66 20 74 68 | 65 20 63 6f 64 65 20 66 |ch of th|e code f|
|000016e0| 6f 72 20 74 68 69 73 20 | 6d 65 74 68 6f 64 20 69 |or this |method i|
|000016f0| 73 20 63 6f 6e 63 65 72 | 6e 65 64 20 77 69 74 68 |s concer|ned with|
|00001700| 20 74 68 65 20 72 65 64 | 75 63 74 69 6f 6e 20 70 | the red|uction p|
|00001710| 72 6f 63 65 73 73 2e 20 | 72 65 64 75 63 74 69 6f |rocess. |reductio|
|00001720| 6e 20 69 73 20 61 20 62 | 69 74 20 74 72 69 63 6b |n is a b|it trick|
|00001730| 79 20 73 69 6e 63 65 20 | 77 65 20 64 6f 6e d5 74 |y since |we don.t|
|00001740| 0d 09 6b 65 65 70 20 70 | 6f 69 6e 74 65 72 73 20 |..keep p|ointers |
|00001750| 74 6f 20 63 68 69 6c 64 | 72 65 6e 20 61 6e 64 20 |to child|ren and |
|00001760| 77 65 20 64 6f 6e d5 74 | 20 61 6c 6c 6f 77 20 67 |we don.t| allow g|
|00001770| 61 70 73 20 69 6e 20 65 | 69 74 68 65 72 20 6f 75 |aps in e|ither ou|
|00001780| 72 20 6e 6f 64 65 20 73 | 74 72 75 63 74 75 72 65 |r node s|tructure|
|00001790| 20 6f 72 20 6f 75 72 20 | 63 6f 6c 6f 72 20 73 74 | or our |color st|
|000017a0| 72 75 63 74 75 72 65 2e | 20 74 68 69 73 20 68 61 |ructure.| this ha|
|000017b0| 73 20 74 68 65 0d 09 62 | 65 6e 65 66 69 74 20 6f |s the..b|enefit o|
|000017c0| 66 20 61 6c 6c 6f 77 69 | 6e 67 20 75 73 20 74 6f |f allowi|ng us to|
|000017d0| 20 61 76 6f 69 64 20 61 | 6c 6c 6f 63 61 74 69 6e | avoid a|llocatin|
|000017e0| 67 20 6f 72 20 64 65 61 | 6c 6c 6f 63 61 74 69 6e |g or dea|llocatin|
|000017f0| 67 20 61 6e 79 20 6d 65 | 6d 6f 72 79 20 77 68 69 |g any me|mory whi|
|00001800| 6c 65 20 77 65 20 61 72 | 65 20 72 65 63 6f 72 64 |le we ar|e record|
|00001810| 69 6e 67 20 63 6f 6c 6f | 72 73 2c 20 62 75 74 20 |ing colo|rs, but |
|00001820| 77 65 20 68 61 76 65 0d | 09 74 6f 20 68 61 76 65 |we have.|.to have|
|00001830| 20 63 6f 64 65 20 74 6f | 20 64 65 61 6c 20 77 69 | code to| deal wi|
|00001840| 74 68 20 74 68 69 6e 67 | 73 20 6c 69 6b 65 20 72 |th thing|s like r|
|00001850| 65 6d 6f 76 69 6e 67 20 | 61 20 63 6f 6c 6f 72 20 |emoving |a color |
|00001860| 28 6f 72 20 61 20 6e 6f | 64 65 29 20 66 72 6f 6d |(or a no|de) from|
|00001870| 20 74 68 65 20 6d 69 64 | 64 6c 65 20 6f 66 20 74 | the mid|dle of t|
|00001880| 68 65 20 63 6f 6c 6f 72 | 42 61 73 65 20 61 72 72 |he color|Base arr|
|00001890| 61 79 2e 20 77 65 20 64 | 6f 0d 09 73 6f 20 62 79 |ay. we d|o..so by|
|000018a0| 20 63 6f 70 79 69 6e 67 | 20 74 68 65 20 6c 61 73 | copying| the las|
|000018b0| 74 20 63 6f 6c 6f 72 20 | 28 6f 72 20 6e 6f 64 65 |t color |(or node|
|000018c0| 29 20 6f 76 65 72 20 74 | 68 65 20 69 74 65 6d 20 |) over t|he item |
|000018d0| 74 68 61 74 20 77 65 20 | 61 72 65 20 72 65 6d 6f |that we |are remo|
|000018e0| 76 69 6e 67 20 61 6e 64 | 20 74 68 65 6e 20 75 70 |ving and| then up|
|000018f0| 64 61 74 69 6e 67 20 74 | 68 61 74 20 69 74 65 6d |dating t|hat item|
|00001900| d5 73 20 70 61 72 65 6e | 74 20 74 6f 0d 09 70 6f |.s paren|t to..po|
|00001910| 69 6e 74 20 74 6f 20 74 | 68 65 20 6e 65 77 20 73 |int to t|he new s|
|00001920| 70 6f 74 2e 20 69 66 20 | 74 68 65 20 69 74 65 6d |pot. if |the item|
|00001930| 20 69 73 20 61 20 63 6f | 6c 6f 72 2c 20 74 68 65 | is a co|lor, the|
|00001940| 6e 20 77 65 20 61 6c 73 | 6f 20 6e 65 65 64 20 74 |n we als|o need t|
|00001950| 6f 20 77 61 6c 6b 20 74 | 68 65 20 63 6f 6c 6f 72 |o walk t|he color|
|00001960| 4c 69 73 74 20 66 6f 72 | 20 74 68 65 20 63 6f 72 |List for| the cor|
|00001970| 72 65 63 74 20 6c 65 76 | 65 6c 20 61 6e 64 20 72 |rect lev|el and r|
|00001980| 65 2d 0d 09 6c 69 6e 6b | 20 74 68 65 20 63 68 61 |e-..link| the cha|
|00001990| 69 6e 20 6f 66 20 63 6f | 6c 6f 72 73 20 74 6f 20 |in of co|lors to |
|000019a0| 73 6b 69 70 20 74 68 65 | 20 72 65 6d 6f 76 65 64 |skip the| removed|
|000019b0| 20 6f 6e 65 2e 0d 0d 09 | 74 68 65 20 63 6f 6c 6f | one....|the colo|
|000019c0| 72 4c 69 73 74 20 61 72 | 72 61 79 73 20 61 72 65 |rList ar|rays are|
|000019d0| 20 63 6f 6e 76 65 6e 69 | 65 6e 74 20 69 6e 20 64 | conveni|ent in d|
|000019e0| 65 74 65 72 6d 69 6e 69 | 6e 67 20 77 68 65 72 65 |etermini|ng where|
|000019f0| 20 74 6f 20 73 74 61 72 | 74 20 63 6f 6d 62 69 6e | to star|t combin|
|00001a00| 69 6e 67 20 6e 6f 64 65 | 73 20 64 75 72 69 6e 67 |ing node|s during|
|00001a10| 20 72 65 64 75 63 74 69 | 6f 6e 2e 20 74 68 65 72 | reducti|on. ther|
|00001a20| 65 20 69 73 20 61 6e 0d | 09 61 72 72 61 79 20 66 |e is an.|.array f|
|00001a30| 6f 72 20 65 61 63 68 20 | 6c 65 76 65 6c 20 61 6e |or each |level an|
|00001a40| 64 20 77 68 65 6e 20 77 | 65 20 6e 65 65 64 20 74 |d when w|e need t|
|00001a50| 6f 20 72 65 64 75 63 65 | 20 63 6f 6c 6f 72 73 2c |o reduce| colors,|
|00001a60| 20 77 65 20 61 6c 77 61 | 79 73 20 73 74 61 72 74 | we alwa|ys start|
|00001a70| 20 77 69 74 68 20 74 68 | 65 20 6d 61 78 69 6d 75 | with th|e maximu|
|00001a80| 6d 4c 65 76 65 6c 20 61 | 72 72 61 79 20 28 6c 65 |mLevel a|rray (le|
|00001a90| 76 65 6c 0d 09 65 69 67 | 68 74 29 20 61 6e 64 20 |vel..eig|ht) and |
|00001aa0| 77 65 20 74 72 79 20 74 | 6f 20 72 65 64 75 63 65 |we try t|o reduce|
|00001ab0| 20 74 68 65 20 66 69 72 | 73 74 20 69 74 65 6d 20 | the fir|st item |
|00001ac0| 69 6e 20 69 74 2e 20 69 | 66 20 74 68 61 74 20 63 |in it. i|f that c|
|00001ad0| 6f 6c 6f 72 d5 73 20 70 | 61 72 65 6e 74 20 68 61 |olor.s p|arent ha|
|00001ae0| 64 20 6d 6f 72 65 20 74 | 68 61 6e 20 6f 6e 65 20 |d more t|han one |
|00001af0| 63 68 69 6c 64 2c 20 74 | 68 65 6e 20 77 65 20 63 |child, t|hen we c|
|00001b00| 61 6e 20 73 61 76 65 0d | 09 61 20 63 6f 6c 6f 72 |an save.|.a color|
|00001b10| 20 62 79 20 63 6f 6d 62 | 69 6e 69 6e 67 20 61 6c | by comb|ining al|
|00001b20| 6c 20 74 68 65 20 63 68 | 69 6c 64 72 65 6e 20 6f |l the ch|ildren o|
|00001b30| 66 20 74 68 69 73 20 70 | 61 72 65 6e 74 20 69 6e |f this p|arent in|
|00001b40| 74 6f 20 61 20 73 69 6e | 67 6c 65 20 61 76 65 72 |to a sin|gle aver|
|00001b50| 61 67 65 64 20 63 6f 6c | 6f 72 20 61 6e 64 20 77 |aged col|or and w|
|00001b60| 65 20 69 6d 65 64 69 61 | 74 65 6c 79 20 70 72 6f |e imedia|tely pro|
|00001b70| 63 65 65 64 20 74 6f 20 | 64 6f 0d 09 73 6f 2e 20 |ceed to |do..so. |
|00001b80| 69 66 20 74 68 65 20 70 | 61 72 65 6e 74 20 68 61 |if the p|arent ha|
|00001b90| 73 20 6f 6e 6c 79 20 6f | 6e 65 20 63 68 69 6c 64 |s only o|ne child|
|00001ba0| 2c 20 74 68 65 6e 20 77 | 65 20 6d 6f 76 65 20 74 |, then w|e move t|
|00001bb0| 6f 20 74 68 65 20 6e 65 | 78 74 20 63 6f 6c 6f 72 |o the ne|xt color|
|00001bc0| 20 69 6e 20 74 68 65 20 | 63 6f 6c 6f 72 4c 69 73 | in the |colorLis|
|00001bd0| 74 20 66 6f 72 20 74 68 | 61 74 20 6c 65 76 65 6c |t for th|at level|
|00001be0| 2e 20 6f 6e 6c 79 20 77 | 68 65 6e 20 77 65 0d 09 |. only w|hen we..|
|00001bf0| 61 72 65 20 75 6e 61 62 | 6c 65 20 74 6f 20 72 65 |are unab|le to re|
|00001c00| 64 75 63 65 20 61 6e 79 | 20 63 6f 6c 6f 72 73 20 |duce any| colors |
|00001c10| 69 6e 20 61 20 67 69 76 | 65 6e 20 6c 65 76 65 6c |in a giv|en level|
|00001c20| 20 64 6f 20 77 65 20 6d | 6f 76 65 20 75 70 20 74 | do we m|ove up t|
|00001c30| 6f 20 74 68 65 20 63 6f | 6c 6f 72 4c 69 73 74 20 |o the co|lorList |
|00001c40| 61 72 72 61 79 20 66 6f | 72 20 74 68 65 20 70 72 |array fo|r the pr|
|00001c50| 65 76 69 6f 75 73 20 6c | 65 76 65 6c 20 61 6e 64 |evious l|evel and|
|00001c60| 0d 09 74 72 79 20 74 6f | 20 72 65 64 75 63 65 20 |..try to| reduce |
|00001c70| 63 6f 6c 6f 72 73 20 66 | 72 6f 6d 20 69 74 2e 0d |colors f|rom it..|
|00001c80| 0d 09 77 68 65 6e 20 77 | 65 20 6d 6f 76 65 20 75 |..when w|e move u|
|00001c90| 70 20 61 20 6c 65 76 65 | 6c 2c 20 77 65 20 6d 75 |p a leve|l, we mu|
|00001ca0| 73 74 20 61 6c 73 6f 20 | 72 65 6d 65 6d 62 65 72 |st also |remember|
|00001cb0| 20 74 6f 20 74 72 79 20 | 72 65 64 75 63 69 6e 67 | to try |reducing|
|00001cc0| 20 74 68 65 20 6e 65 78 | 74 20 6c 65 76 65 6c d5 | the nex|t level.|
|00001cd0| 73 20 63 6f 6c 6f 72 73 | 20 62 79 20 74 77 6f 20 |s colors| by two |
|00001ce0| 6c 65 76 65 6c 73 2c 20 | 62 65 66 6f 72 65 0d 09 |levels, |before..|
|00001cf0| 61 63 74 75 61 6c 6c 79 | 20 67 69 76 69 6e 67 20 |actually| giving |
|00001d00| 75 70 20 61 72 65 20 70 | 72 6f 63 65 65 64 69 6e |up are p|roceedin|
|00001d10| 67 20 75 70 20 61 6e 6f | 74 68 65 72 20 6c 65 76 |g up ano|ther lev|
|00001d20| 65 6c 2e 20 66 6f 72 20 | 65 78 61 6d 70 6c 65 2c |el. for |example,|
|00001d30| 20 77 65 20 6d 69 67 68 | 74 20 68 61 76 65 20 33 | we migh|t have 3|
|00001d40| 20 6c 65 76 65 6c 20 38 | 20 63 6f 6c 6f 72 73 20 | level 8| colors |
|00001d50| 74 68 61 74 20 63 61 6e | d5 74 20 62 65 0d 09 72 |that can|.t be..r|
|00001d60| 65 64 75 63 65 64 20 74 | 6f 20 6c 65 76 65 6c 20 |educed t|o level |
|00001d70| 37 20 28 6f 72 20 61 74 | 20 6c 65 61 73 74 20 77 |7 (or at| least w|
|00001d80| 65 20 77 6f 75 6c 64 6e | d5 74 20 67 61 69 6e 20 |e wouldn|.t gain |
|00001d90| 61 20 63 6f 6c 6f 72 29 | 20 61 6e 64 20 35 20 6c |a color)| and 5 l|
|00001da0| 65 76 65 6c 20 37 20 6e | 6f 64 65 73 20 74 68 61 |evel 7 n|odes tha|
|00001db0| 74 20 61 6c 73 6f 20 63 | 61 6e d5 74 20 62 65 20 |t also c|an.t be |
|00001dc0| 72 65 64 75 63 65 64 2e | 20 61 66 74 65 72 0d 09 |reduced.| after..|
|00001dd0| 63 68 65 63 6b 69 6e 67 | 20 74 68 65 20 6c 61 73 |checking| the las|
|00001de0| 74 20 6c 65 76 65 6c 20 | 37 20 6e 6f 64 65 2c 20 |t level |7 node, |
|00001df0| 77 65 20 77 6f 75 6c 64 | 20 6c 6f 6f 6b 20 61 67 |we would| look ag|
|00001e00| 61 69 6e 20 61 74 20 74 | 68 65 20 6c 65 76 65 6c |ain at t|he level|
|00001e10| 20 38 20 6e 6f 64 65 73 | 2c 20 74 68 69 73 20 74 | 8 nodes|, this t|
|00001e20| 69 6d 65 20 74 72 79 69 | 6e 67 20 74 6f 20 72 65 |ime tryi|ng to re|
|00001e30| 64 75 63 65 20 74 68 65 | 6d 20 61 6c 6c 20 74 68 |duce the|m all th|
|00001e40| 65 0d 09 77 61 79 20 75 | 70 20 74 6f 20 6c 65 76 |e..way u|p to lev|
|00001e50| 65 6c 20 36 2c 20 77 68 | 65 72 65 20 74 68 65 79 |el 6, wh|ere they|
|00001e60| 20 77 6f 75 6c 64 20 65 | 6e 63 6f 6d 70 61 73 73 | would e|ncompass|
|00001e70| 20 73 69 78 74 79 2d 66 | 6f 75 72 20 6c 65 76 65 | sixty-f|our leve|
|00001e80| 6c 20 38 20 52 47 42 20 | 63 75 62 65 73 2e 20 69 |l 8 RGB |cubes. i|
|00001e90| 66 20 77 65 20 63 61 6e | 20 73 61 76 65 20 61 20 |f we can| save a |
|00001ea0| 63 6f 6c 6f 72 20 62 79 | 20 72 65 64 75 63 69 6e |color by| reducin|
|00001eb0| 67 0d 09 61 20 6c 65 76 | 65 6c 20 38 20 63 6f 6c |g..a lev|el 8 col|
|00001ec0| 6f 72 20 74 77 6f 20 6c | 65 76 65 6c 73 20 75 70 |or two l|evels up|
|00001ed0| 20 74 6f 20 6c 65 76 65 | 6c 20 73 69 78 2c 20 77 | to leve|l six, w|
|00001ee0| 65 20 77 69 6c 6c 20 64 | 6f 20 73 6f 20 62 65 66 |e will d|o so bef|
|00001ef0| 6f 72 65 20 70 72 6f 63 | 65 65 64 69 6e 67 20 74 |ore proc|eeding t|
|00001f00| 6f 20 74 68 65 20 6c 65 | 76 65 6c 20 36 20 6c 69 |o the le|vel 6 li|
|00001f10| 73 74 20 61 6e 64 20 74 | 72 79 69 6e 67 20 74 6f |st and t|rying to|
|00001f20| 20 72 65 64 75 63 65 0d | 09 6c 65 76 65 6c 20 36 | reduce.|.level 6|
|00001f30| 20 63 6f 6c 6f 72 73 20 | 74 6f 20 6c 65 76 65 6c | colors |to level|
|00001f40| 20 35 2e 0d 0d 09 74 68 | 65 72 65 20 69 73 20 6c | 5....th|ere is l|
|00001f50| 6f 74 73 20 6f 66 20 72 | 6f 6f 6d 20 66 6f 72 20 |ots of r|oom for |
|00001f60| 69 6d 70 72 6f 76 65 6d | 65 6e 74 20 69 6e 20 74 |improvem|ent in t|
|00001f70| 68 65 20 61 6c 67 6f 72 | 69 74 68 6d 20 74 68 61 |he algor|ithm tha|
|00001f80| 74 20 63 68 6f 73 65 73 | 20 77 68 69 63 68 20 63 |t choses| which c|
|00001f90| 6f 6c 6f 72 73 20 74 6f | 20 72 65 64 75 63 65 2e |olors to| reduce.|
|00001fa0| 20 63 75 72 72 65 6e 74 | 6c 79 2c 20 77 65 20 64 | current|ly, we d|
|00001fb0| 6f 6e d5 74 0d 09 6c 6f | 6f 6b 20 61 74 20 61 6c |on.t..lo|ok at al|
|00001fc0| 6c 20 61 74 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |l at the| number |
|00001fd0| 6f 66 20 73 6f 75 72 63 | 65 20 63 6f 64 65 73 20 |of sourc|e codes |
|00001fe0| 63 6f 6d 62 69 6e 65 64 | 20 69 6e 74 6f 20 61 20 |combined| into a |
|00001ff0| 63 6f 6c 6f 72 20 65 6e | 74 72 79 3b 20 74 68 69 |color en|try; thi|
|00002000| 73 20 6c 65 74 73 20 75 | 73 20 70 72 65 73 65 72 |s lets u|s preser|
|00002010| 76 65 20 73 6d 61 6c 6c | 20 73 70 6c 61 73 68 65 |ve small| splashe|
|00002020| 73 20 6f 66 20 61 0d 09 | 64 72 61 73 74 69 63 6c |s of a..|drasticl|
|00002030| 79 20 64 69 66 66 65 72 | 65 6e 74 20 63 6f 6c 6f |y differ|ent colo|
|00002040| 72 20 61 74 20 74 68 65 | 20 63 6f 73 74 20 6f 66 |r at the| cost of|
|00002050| 20 6d 75 64 64 79 69 6e | 67 20 75 70 20 74 68 65 | muddyin|g up the|
|00002060| 20 63 6f 6c 6f 72 73 20 | 74 68 61 74 20 6d 61 6b | colors |that mak|
|00002070| 65 20 75 70 20 74 68 65 | 20 62 75 6c 6b 20 6f 66 |e up the| bulk of|
|00002080| 20 74 68 65 20 69 6d 61 | 67 65 2e 0d 0d 09 6e 6f | the ima|ge....no|
|00002090| 74 65 20 74 68 61 74 20 | 77 65 20 72 65 6d 6f 76 |te that |we remov|
|000020a0| 65 20 63 6f 6c 6f 72 73 | 20 69 6d 6d 65 64 69 61 |e colors| immedia|
|000020b0| 74 65 6c 79 20 77 68 65 | 6e 20 77 65 20 63 6f 6d |tely whe|n we com|
|000020c0| 62 69 6e 65 20 74 68 65 | 6d 2c 20 62 75 74 20 77 |bine the|m, but w|
|000020d0| 65 20 6f 6e 6c 79 20 6d | 61 72 6b 20 6e 6f 64 65 |e only m|ark node|
|000020e0| 73 20 61 73 20 6f 62 73 | 6f 6c 65 74 65 20 77 69 |s as obs|olete wi|
|000020f0| 74 68 6f 75 74 0d 09 72 | 65 6d 6f 76 69 6e 67 20 |thout..r|emoving |
|00002100| 74 68 65 6d 20 6f 6e 20 | 74 68 65 20 73 70 6f 74 |them on |the spot|
|00002110| 2e 20 74 68 69 73 20 69 | 73 20 73 6f 6c 65 6c 79 |. this i|s solely|
|00002120| 20 62 65 63 61 75 73 65 | 20 74 68 65 20 52 65 64 | because| the Red|
|00002130| 75 63 65 4e 6f 64 65 20 | 72 6f 75 74 69 6e 65 20 |uceNode |routine |
|00002140| 69 73 20 72 65 63 75 72 | 73 69 76 65 20 61 6e 64 |is recur|sive and|
|00002150| 20 6b 65 65 70 73 20 77 | 68 69 63 68 20 6e 6f 64 | keeps w|hich nod|
|00002160| 65 0d 09 69 74 20 69 73 | 20 77 6f 72 6b 69 6e 67 |e..it is| working|
|00002170| 20 77 69 74 68 20 6f 6e | 20 74 68 65 20 73 74 61 | with on| the sta|
|00002180| 63 6b 2e 20 74 68 69 73 | 20 77 6f 75 6c 64 20 62 |ck. this| would b|
|00002190| 65 20 61 20 70 72 6f 62 | 6c 65 6d 20 69 66 20 77 |e a prob|lem if w|
|000021a0| 68 69 6c 65 20 72 65 6d | 6f 76 69 6e 67 20 61 20 |hile rem|oving a |
|000021b0| 6e 6f 64 65 2c 20 77 65 | 20 6e 65 65 64 20 74 6f |node, we| need to|
|000021c0| 20 72 65 6f 72 64 65 72 | 20 74 68 65 20 6e 6f 64 | reorder| the nod|
|000021d0| 65 73 0d 09 74 68 61 74 | 20 61 72 65 20 72 65 66 |es..that| are ref|
|000021e0| 65 72 65 6e 63 65 64 20 | 62 79 20 64 69 66 66 65 |erenced |by diffe|
|000021f0| 72 65 6e 74 20 69 6e 63 | 61 72 6e 61 74 69 6f 6e |rent inc|arnation|
|00002200| 73 20 6f 66 20 52 65 64 | 75 63 65 4e 6f 64 65 2e |s of Red|uceNode.|
|00002210| 20 62 79 20 6d 61 72 6b | 69 6e 67 20 61 6c 6c 20 | by mark|ing all |
|00002220| 74 68 65 20 6e 6f 64 65 | 73 20 61 73 20 6f 62 73 |the node|s as obs|
|00002230| 6f 6c 65 74 65 2c 20 77 | 65 20 63 61 6e 0d 09 70 |olete, w|e can..p|
|00002240| 6f 73 74 70 6f 6e 65 20 | 72 65 6d 6f 76 69 6e 67 |ostpone |removing|
|00002250| 20 74 68 65 6d 20 75 6e | 74 69 6c 20 6e 6f 2d 6f | them un|til no-o|
|00002260| 6e 65 20 68 61 73 20 61 | 6e 79 20 72 65 66 65 72 |ne has a|ny refer|
|00002270| 65 6e 63 65 73 20 28 62 | 65 73 69 64 65 73 20 74 |ences (b|esides t|
|00002280| 68 65 20 74 72 65 65 20 | 73 74 72 75 63 74 75 72 |he tree |structur|
|00002290| 65 20 69 74 73 65 6c 66 | 29 20 61 6e 64 20 69 74 |e itself|) and it|
|000022a0| 20 69 73 20 73 61 66 65 | 20 74 6f 0d 09 6d 6f 76 | is safe| to..mov|
|000022b0| 65 20 6e 6f 64 65 73 2e | 0d 2a 2f 0d 2f 2a 2d 2d |e nodes.|.*/./*--|
|000022c0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000022d0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000022e0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|000022f0| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00002300| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00002310| 2d 2d 2d 2d 2d 2d 2d 2d | 2d 2d 2d 2d 2d 2d 2d 2d |--------|--------|
|00002320| 2d 2d 2d 2d 2d 2a 2f 0d | 0d 0d 2f 2a 20 66 75 6e |-----*/.|../* fun|
|00002330| 63 74 69 6f 6e 20 70 72 | 6f 74 6f 74 79 70 65 73 |ction pr|ototypes|
|00002340| 20 66 6f 72 20 74 68 65 | 20 6d 61 69 6e 20 73 75 | for the| main su|
|00002350| 62 72 6f 75 74 69 6e 65 | 73 20 74 68 61 74 20 70 |broutine|s that p|
|00002360| 69 63 74 75 72 65 20 75 | 74 69 6c 69 74 69 65 73 |icture u|tilities|
|00002370| 20 77 69 6c 6c 20 63 61 | 6c 6c 2e 20 2a 2f 0d 0d | will ca|ll. */..|
|00002380| 70 61 73 63 61 6c 20 73 | 68 6f 72 74 20 49 6e 69 |pascal s|hort Ini|
|00002390| 74 4f 63 74 72 65 65 28 | 73 68 6f 72 74 20 63 6f |tOctree(|short co|
|000023a0| 6c 6f 72 73 52 65 71 75 | 65 73 74 65 64 2c 20 6c |lorsRequ|ested, l|
|000023b0| 6f 6e 67 20 2a 64 61 74 | 61 48 61 6e 64 6c 65 50 |ong *dat|aHandleP|
|000023c0| 74 72 2c 20 73 68 6f 72 | 74 20 2a 62 61 6e 6b 54 |tr, shor|t *bankT|
|000023d0| 79 70 65 29 3b 0d 70 61 | 73 63 61 6c 20 73 68 6f |ype);.pa|scal sho|
|000023e0| 72 74 20 52 65 63 6f 72 | 64 4f 63 74 72 65 65 43 |rt Recor|dOctreeC|
|000023f0| 6f 6c 6f 72 73 28 6c 6f | 6e 67 20 64 61 74 61 48 |olors(lo|ng dataH|
|00002400| 61 6e 64 6c 65 2c 20 52 | 47 42 43 6f 6c 6f 72 20 |andle, R|GBColor |
|00002410| 2a 63 6f 6c 6f 72 50 74 | 72 2c 20 6c 6f 6e 67 20 |*colorPt|r, long |
|00002420| 63 6f 6c 6f 72 43 6f 75 | 6e 74 2c 20 6c 6f 6e 67 |colorCou|nt, long|
|00002430| 20 2a 75 6e 69 71 75 65 | 43 6f 6c 6f 72 73 50 74 | *unique|ColorsPt|
|00002440| 72 29 3b 0d 70 61 73 63 | 61 6c 20 73 68 6f 72 74 |r);.pasc|al short|
|00002450| 20 43 61 6c 63 4f 63 74 | 72 65 65 54 61 62 6c 65 | CalcOct|reeTable|
|00002460| 28 6c 6f 6e 67 20 64 61 | 74 61 48 61 6e 64 6c 65 |(long da|taHandle|
|00002470| 2c 20 73 68 6f 72 74 20 | 63 6f 6c 6f 72 73 52 65 |, short |colorsRe|
|00002480| 71 75 65 73 74 65 64 2c | 20 73 68 6f 72 74 20 2a |quested,| short *|
|00002490| 63 6f 6c 6f 72 42 61 6e | 6b 50 74 72 2c 20 43 6f |colorBan|kPtr, Co|
|000024a0| 6c 6f 72 53 70 65 63 20 | 2a 72 65 73 75 6c 74 50 |lorSpec |*resultP|
|000024b0| 74 72 29 3b 0d 70 61 73 | 63 61 6c 20 73 68 6f 72 |tr);.pas|cal shor|
|000024c0| 74 20 4b 69 6c 6c 4f 63 | 74 72 65 65 28 6c 6f 6e |t KillOc|tree(lon|
|000024d0| 67 20 64 61 74 61 48 61 | 6e 64 6c 65 29 3b 0d 0d |g dataHa|ndle);..|
|000024e0| 0d 0d 2f 2a 20 6f 75 72 | 20 6d 61 69 6e 20 64 69 |../* our| main di|
|000024f0| 73 70 61 74 63 68 65 72 | 2e 20 70 69 63 74 75 72 |spatcher|. pictur|
|00002500| 65 20 75 74 69 6c 69 74 | 69 65 73 20 77 69 6c 6c |e utilit|ies will|
|00002510| 20 63 61 6c 6c 20 74 68 | 69 73 20 77 69 74 68 20 | call th|is with |
|00002520| 74 68 65 20 73 65 6c 65 | 63 74 6f 72 20 66 6f 72 |the sele|ctor for|
|00002530| 20 77 68 69 63 68 20 70 | 69 63 6b 20 66 75 6e 63 | which p|ick func|
|00002540| 74 69 6f 6e 20 74 6f 20 | 63 61 6c 6c 20 69 6e 20 |tion to |call in |
|00002550| 44 30 2e 77 20 2a 2f 0d | 76 6f 69 64 20 6d 61 69 |D0.w */.|void mai|
|00002560| 6e 28 76 6f 69 64 29 0d | 7b 0d 09 61 73 6d 20 7b |n(void).|{..asm {|
|00002570| 0d 09 09 6c 73 6c 2e 77 | 09 09 23 32 2c 20 64 30 |...lsl.w|..#2, d0|
|00002580| 0d 09 09 6c 65 61 09 09 | 40 74 61 62 6c 65 2c 20 |...lea..|@table, |
|00002590| 61 30 0d 09 09 6a 6d 70 | 09 09 30 28 61 30 2c 20 |a0...jmp|..0(a0, |
|000025a0| 64 30 2e 77 29 0d 0d 40 | 74 61 62 6c 65 09 6a 6d |d0.w)..@|table.jm|
|000025b0| 70 09 09 49 6e 69 74 4f | 63 74 72 65 65 0d 09 09 |p..InitO|ctree...|
|000025c0| 6a 6d 70 09 09 52 65 63 | 6f 72 64 4f 63 74 72 65 |jmp..Rec|ordOctre|
|000025d0| 65 43 6f 6c 6f 72 73 0d | 09 09 6a 6d 70 09 09 43 |eColors.|..jmp..C|
|000025e0| 61 6c 63 4f 63 74 72 65 | 65 54 61 62 6c 65 0d 09 |alcOctre|eTable..|
|000025f0| 09 6a 6d 70 09 09 4b 69 | 6c 6c 4f 63 74 72 65 65 |.jmp..Ki|llOctree|
|00002600| 0d 09 7d 0d 7d 0d 0d 0d | 2f 2a 09 74 68 65 73 65 |..}.}...|/*.these|
|00002610| 20 66 75 6e 63 74 69 6f | 6e 73 20 76 61 6c 69 64 | functio|ns valid|
|00002620| 61 74 65 20 74 68 65 20 | 6d 61 69 6e 20 6f 63 74 |ate the |main oct|
|00002630| 72 65 65 20 73 74 72 75 | 63 74 75 72 65 20 74 6f |ree stru|cture to|
|00002640| 20 6d 61 6b 65 20 73 75 | 72 65 20 74 68 61 74 20 | make su|re that |
|00002650| 61 6c 6c 20 74 68 65 20 | 6e 6f 64 65 73 20 70 6f |all the |nodes po|
|00002660| 69 6e 74 20 74 6f 20 76 | 61 6c 69 64 20 65 6e 74 |int to v|alid ent|
|00002670| 72 69 65 73 20 69 6e 20 | 65 69 74 68 65 72 20 74 |ries in |either t|
|00002680| 68 65 0d 09 6e 6f 64 65 | 20 74 61 62 6c 65 20 6f |he..node| table o|
|00002690| 72 20 69 6e 20 74 68 65 | 20 63 6f 6c 6f 72 20 74 |r in the| color t|
|000026a0| 61 62 6c 65 2e 20 74 68 | 65 79 20 61 6c 73 6f 20 |able. th|ey also |
|000026b0| 6d 61 6b 65 20 73 75 72 | 65 20 74 68 61 74 20 65 |make sur|e that e|
|000026c0| 61 63 68 20 6e 6f 64 65 | d5 73 20 28 6f 72 20 63 |ach node|.s (or c|
|000026d0| 6f 6c 6f 72 d5 73 29 20 | 70 61 72 65 6e 74 20 66 |olor.s) |parent f|
|000026e0| 69 65 6c 64 20 72 65 61 | 6c 6c 79 20 64 6f 65 73 |ield rea|lly does|
|000026f0| 20 70 6f 69 6e 74 20 74 | 6f 20 74 68 65 0d 09 6e | point t|o the..n|
|00002700| 6f 64 65 20 74 68 61 74 | 20 63 6f 6e 74 61 69 6e |ode that| contain|
|00002710| 73 20 74 68 65 6d 20 61 | 6e 64 20 74 68 65 79 20 |s them a|nd they |
|00002720| 65 6e 73 75 72 65 20 74 | 68 61 74 20 61 6c 6c 20 |ensure t|hat all |
|00002730| 74 68 65 20 63 6f 6c 6f | 72 20 6c 69 73 74 73 20 |the colo|r lists |
|00002740| 28 6f 6e 65 20 66 6f 72 | 20 65 61 63 68 20 6c 65 |(one for| each le|
|00002750| 76 65 6c 29 20 63 6f 6e | 74 61 69 6e 20 6f 6e 6c |vel) con|tain onl|
|00002760| 79 20 63 6f 6c 6f 72 73 | 20 74 68 61 74 20 61 72 |y colors| that ar|
|00002770| 65 20 76 61 6c 69 64 0d | 09 65 6e 74 72 69 65 73 |e valid.|.entries|
|00002780| 20 69 6e 20 74 68 65 20 | 63 6f 6c 6f 72 20 74 61 | in the |color ta|
|00002790| 62 6c 65 20 2a 2f 0d 0d | 23 69 66 64 65 66 20 64 |ble */..|#ifdef d|
|000027a0| 65 62 75 67 67 69 6e 67 | 0d 09 73 74 61 74 69 63 |ebugging|..static|
|000027b0| 20 76 6f 69 64 20 56 61 | 6c 69 64 61 74 65 4e 6f | void Va|lidateNo|
|000027c0| 64 65 28 6f 63 74 72 65 | 65 20 2a 74 72 65 65 2c |de(octre|e *tree,|
|000027d0| 20 6f 63 74 72 65 65 4e | 6f 64 65 20 2a 6e 6f 64 | octreeN|ode *nod|
|000027e0| 65 29 0d 09 7b 0d 09 09 | 73 68 6f 72 74 20 63 6f |e)..{...|short co|
|000027f0| 75 6e 74 65 72 20 3d 20 | 38 3b 0d 09 09 73 68 6f |unter = |8;...sho|
|00002800| 72 74 20 6e 6f 64 65 49 | 6e 64 65 78 3b 0d 0d 09 |rt nodeI|ndex;...|
|00002810| 09 49 66 44 65 62 75 67 | 28 6e 6f 64 65 2d 3e 63 |.IfDebug|(node->c|
|00002820| 68 69 6c 64 72 65 6e 20 | 3e 20 38 2c 20 22 5c 70 |hildren |> 8, "\p|
|00002830| 74 6f 6f 20 6d 61 6e 79 | 20 63 68 69 6c 64 72 65 |too many| childre|
|00002840| 6e 20 69 6e 20 6e 6f 64 | 65 22 29 3b 0d 09 09 49 |n in nod|e");...I|
|00002850| 66 44 65 62 75 67 28 6e | 6f 64 65 2d 3e 70 61 72 |fDebug(n|ode->par|
|00002860| 65 6e 74 20 21 3d 20 65 | 6d 70 74 79 4e 6f 64 65 |ent != e|mptyNode|
|00002870| 20 26 26 20 6e 6f 64 65 | 2d 3e 70 61 72 65 6e 74 | && node|->parent|
|00002880| 20 3e 3d 20 74 72 65 65 | 2d 3e 6e 6f 64 65 73 2c | >= tree|->nodes,|
|00002890| 20 22 5c 70 69 6e 76 61 | 6c 69 64 20 6e 6f 64 65 | "\pinva|lid node|
|000028a0| 20 70 61 72 65 6e 74 22 | 29 3b 0d 0d 09 09 6e 6f | parent"|);....no|
|000028b0| 64 65 49 6e 64 65 78 20 | 3d 20 6e 6f 64 65 20 2d |deIndex |= node -|
|000028c0| 20 26 74 72 65 65 2d 3e | 6e 6f 64 65 42 61 73 65 | &tree->|nodeBase|
|000028d0| 5b 30 5d 3b 0d 09 09 77 | 68 69 6c 65 28 20 2d 2d |[0];...w|hile( --|
|000028e0| 63 6f 75 6e 74 65 72 20 | 3e 3d 20 30 20 29 20 7b |counter |>= 0 ) {|
|000028f0| 0d 09 09 09 73 68 6f 72 | 74 20 63 68 69 6c 64 49 |....shor|t childI|
|00002900| 6e 64 65 78 20 3d 20 6e | 6f 64 65 2d 3e 6c 65 61 |ndex = n|ode->lea|
|00002910| 66 5b 63 6f 75 6e 74 65 | 72 5d 3b 0d 09 09 09 69 |f[counte|r];....i|
|00002920| 66 28 20 63 68 69 6c 64 | 49 6e 64 65 78 20 21 3d |f( child|Index !=|
|00002930| 20 65 6d 70 74 79 4e 6f | 64 65 20 29 20 7b 0d 09 | emptyNo|de ) {..|
|00002940| 09 09 09 69 66 28 20 63 | 68 69 6c 64 49 6e 64 65 |...if( c|hildInde|
|00002950| 78 20 3e 3d 20 30 20 29 | 20 7b 0d 09 09 09 09 09 |x >= 0 )| {......|
|00002960| 6f 63 74 72 65 65 4e 6f | 64 65 20 2a 63 68 69 6c |octreeNo|de *chil|
|00002970| 64 3b 0d 09 09 09 09 09 | 49 66 44 65 62 75 67 28 |d;......|IfDebug(|
|00002980| 63 68 69 6c 64 49 6e 64 | 65 78 20 3e 3d 20 74 72 |childInd|ex >= tr|
|00002990| 65 65 2d 3e 6e 6f 64 65 | 73 2c 20 22 5c 70 69 6e |ee->node|s, "\pin|
|000029a0| 76 61 6c 69 64 20 6e 6f | 64 65 20 63 68 69 6c 64 |valid no|de child|
|000029b0| 22 29 3b 0d 09 09 09 09 | 09 63 68 69 6c 64 20 3d |");.....|.child =|
|000029c0| 20 26 74 72 65 65 2d 3e | 6e 6f 64 65 42 61 73 65 | &tree->|nodeBase|
|000029d0| 5b 63 68 69 6c 64 49 6e | 64 65 78 5d 3b 0d 09 09 |[childIn|dex];...|
|000029e0| 09 09 09 69 66 28 20 63 | 68 69 6c 64 2d 3e 63 68 |...if( c|hild->ch|
|000029f0| 69 6c 64 72 65 6e 20 21 | 3d 20 6f 62 73 6f 6c 65 |ildren !|= obsole|
|00002a00| 74 65 4e 6f 64 65 20 29 | 20 7b 0d 09 09 09 09 09 |teNode )| {......|
|00002a10| 09 49 66 44 65 62 75 67 | 28 63 68 69 6c 64 2d 3e |.IfDebug|(child->|
|00002a20| 70 61 72 65 6e 74 20 21 | 3d 20 6e 6f 64 65 49 6e |parent !|= nodeIn|
|00002a30| 64 65 78 2c 20 22 5c 70 | 63 68 69 6c 64 20 6e 6f |dex, "\p|child no|
|00002a40| 64 65 20 64 6f 65 73 6e | 74 20 62 65 6c 6f 6e 67 |de doesn|t belong|
|00002a50| 20 74 6f 20 70 61 72 65 | 6e 74 22 29 3b 0d 09 09 | to pare|nt");...|
|00002a60| 09 09 09 09 56 61 6c 69 | 64 61 74 65 4e 6f 64 65 |....Vali|dateNode|
|00002a70| 28 74 72 65 65 2c 20 63 | 68 69 6c 64 29 3b 0d 09 |(tree, c|hild);..|
|00002a80| 09 09 09 09 7d 0d 09 09 | 09 09 7d 20 65 6c 73 65 |....}...|..} else|
|00002a90| 20 7b 0d 09 09 09 09 09 | 6f 63 74 72 65 65 43 6f | {......|octreeCo|
|00002aa0| 6c 6f 72 20 2a 63 68 69 | 6c 64 3b 0d 09 09 09 09 |lor *chi|ld;.....|
|00002ab0| 09 63 68 69 6c 64 49 6e | 64 65 78 20 3d 20 7e 63 |.childIn|dex = ~c|
|00002ac0| 68 69 6c 64 49 6e 64 65 | 78 3b 0d 09 09 09 09 09 |hildInde|x;......|
|00002ad0| 49 66 44 65 62 75 67 28 | 63 68 69 6c 64 49 6e 64 |IfDebug(|childInd|
|00002ae0| 65 78 20 3e 3d 20 74 72 | 65 65 2d 3e 63 6f 6c 6f |ex >= tr|ee->colo|
|00002af0| 72 73 2c 20 22 5c 70 69 | 6e 76 61 6c 69 64 20 63 |rs, "\pi|nvalid c|
|00002b00| 6f 6c 6f 72 20 63 68 69 | 6c 64 22 29 3b 0d 09 09 |olor chi|ld");...|
|00002b10| 09 09 09 63 68 69 6c 64 | 20 3d 20 26 74 72 65 65 |...child| = &tree|
|00002b20| 2d 3e 63 6f 6c 6f 72 42 | 61 73 65 5b 63 68 69 6c |->colorB|ase[chil|
|00002b30| 64 49 6e 64 65 78 5d 3b | 0d 09 09 09 09 09 49 66 |dIndex];|......If|
|00002b40| 44 65 62 75 67 28 63 68 | 69 6c 64 2d 3e 70 61 72 |Debug(ch|ild->par|
|00002b50| 65 6e 74 20 21 3d 20 6e | 6f 64 65 49 6e 64 65 78 |ent != n|odeIndex|
|00002b60| 2c 20 22 5c 70 63 68 69 | 6c 64 20 63 6f 6c 6f 72 |, "\pchi|ld color|
|00002b70| 20 64 6f 65 73 6e 74 20 | 62 65 6c 6f 6e 67 20 74 | doesnt |belong t|
|00002b80| 6f 20 70 61 72 65 6e 74 | 22 29 3b 0d 09 09 09 09 |o parent|");.....|
|00002b90| 09 49 66 44 65 62 75 67 | 28 63 68 69 6c 64 2d 3e |.IfDebug|(child->|
|00002ba0| 6c 65 76 65 6c 20 3e 20 | 6d 61 78 69 6d 75 6d 4c |level > |maximumL|
|00002bb0| 65 76 65 6c 2c 20 22 5c | 70 63 6f 6c 6f 72 20 6c |evel, "\|pcolor l|
|00002bc0| 65 76 65 6c 20 69 73 20 | 69 6e 76 61 6c 69 64 22 |evel is |invalid"|
|00002bd0| 29 3b 0d 09 09 09 09 09 | 49 66 44 65 62 75 67 28 |);......|IfDebug(|
|00002be0| 63 68 69 6c 64 2d 3e 6e | 65 78 74 20 21 3d 20 65 |child->n|ext != e|
|00002bf0| 6d 70 74 79 4e 6f 64 65 | 20 26 26 20 63 68 69 6c |mptyNode| && chil|
|00002c00| 64 2d 3e 6e 65 78 74 20 | 3e 3d 20 74 72 65 65 2d |d->next |>= tree-|
|00002c10| 3e 63 6f 6c 6f 72 73 2c | 20 22 5c 70 63 6f 6c 6f |>colors,| "\pcolo|
|00002c20| 72 20 6e 65 78 74 20 66 | 69 65 6c 64 20 69 73 20 |r next f|ield is |
|00002c30| 69 6e 76 61 6c 69 64 22 | 29 3b 0d 09 09 09 09 7d |invalid"|);.....}|
|00002c40| 0d 09 09 09 7d 0d 09 09 | 7d 0d 09 7d 0d 0d 09 73 |....}...|}..}...s|
|00002c50| 74 61 74 69 63 20 76 6f | 69 64 20 56 61 6c 69 64 |tatic vo|id Valid|
|00002c60| 61 74 65 43 6f 6c 6f 72 | 4c 69 73 74 28 6f 63 74 |ateColor|List(oct|
|00002c70| 72 65 65 20 2a 74 72 65 | 65 2c 20 73 68 6f 72 74 |ree *tre|e, short|
|00002c80| 20 63 6f 6c 6f 72 49 6e | 64 65 78 29 0d 09 7b 0d | colorIn|dex)..{.|
|00002c90| 09 09 73 68 6f 72 74 20 | 6c 65 76 65 6c 20 3d 20 |..short |level = |
|00002ca0| 2d 31 3b 0d 09 09 77 68 | 69 6c 65 28 20 63 6f 6c |-1;...wh|ile( col|
|00002cb0| 6f 72 49 6e 64 65 78 20 | 21 3d 20 65 6d 70 74 79 |orIndex |!= empty|
|00002cc0| 4e 6f 64 65 20 29 20 7b | 0d 09 09 09 6f 63 74 72 |Node ) {|....octr|
|00002cd0| 65 65 43 6f 6c 6f 72 20 | 2a 63 6f 6c 6f 72 3b 0d |eeColor |*color;.|
|00002ce0| 09 09 09 49 66 44 65 62 | 75 67 28 63 6f 6c 6f 72 |...IfDeb|ug(color|
|00002cf0| 49 6e 64 65 78 20 3e 3d | 20 74 72 65 65 2d 3e 63 |Index >=| tree->c|
|00002d00| 6f 6c 6f 72 73 2c 20 22 | 5c 70 69 6e 76 61 6c 69 |olors, "|\pinvali|
|00002d10| 64 20 63 6f 6c 6f 72 20 | 69 6e 20 63 6f 6c 6f 72 |d color |in color|
|00002d20| 20 6c 69 73 74 22 29 3b | 0d 09 09 09 63 6f 6c 6f | list");|....colo|
|00002d30| 72 20 3d 20 26 74 72 65 | 65 2d 3e 63 6f 6c 6f 72 |r = &tre|e->color|
|00002d40| 42 61 73 65 5b 63 6f 6c | 6f 72 49 6e 64 65 78 5d |Base[col|orIndex]|
|00002d50| 3b 0d 09 09 09 49 66 44 | 65 62 75 67 28 63 6f 6c |;....IfD|ebug(col|
|00002d60| 6f 72 2d 3e 6c 65 76 65 | 6c 20 3e 20 6d 61 78 69 |or->leve|l > maxi|
|00002d70| 6d 75 6d 4c 65 76 65 6c | 2c 20 22 5c 70 63 6f 6c |mumLevel|, "\pcol|
|00002d80| 6f 72 20 6c 65 76 65 6c | 20 69 73 20 69 6e 76 61 |or level| is inva|
|00002d90| 6c 69 64 22 29 3b 0d 09 | 09 09 69 66 28 20 6c 65 |lid");..|..if( le|
|00002da0| 76 65 6c 20 3c 20 30 20 | 29 0d 09 09 09 09 6c 65 |vel < 0 |).....le|
|00002db0| 76 65 6c 20 3d 20 63 6f | 6c 6f 72 2d 3e 6c 65 76 |vel = co|lor->lev|
|00002dc0| 65 6c 3b 0d 09 09 09 49 | 66 44 65 62 75 67 28 63 |el;....I|fDebug(c|
|00002dd0| 6f 6c 6f 72 2d 3e 6c 65 | 76 65 6c 20 21 3d 20 6c |olor->le|vel != l|
|00002de0| 65 76 65 6c 2c 20 22 5c | 70 63 6f 6c 6f 72 20 6e |evel, "\|pcolor n|
|00002df0| 6f 74 20 61 74 20 73 61 | 6d 65 20 6c 65 76 65 6c |ot at sa|me level|
|00002e00| 20 61 73 20 74 68 65 20 | 72 65 73 74 20 6f 66 20 | as the |rest of |
|00002e10| 74 68 65 20 6c 69 73 74 | 22 29 3b 0d 09 09 09 63 |the list|");....c|
|00002e20| 6f 6c 6f 72 49 6e 64 65 | 78 20 3d 20 63 6f 6c 6f |olorInde|x = colo|
|00002e30| 72 2d 3e 6e 65 78 74 3b | 0d 09 09 7d 0d 09 7d 0d |r->next;|...}..}.|
|00002e40| 0d 09 73 74 61 74 69 63 | 20 76 6f 69 64 20 56 61 |..static| void Va|
|00002e50| 6c 69 64 61 74 65 4f 63 | 74 72 65 65 28 6f 63 74 |lidateOc|tree(oct|
|00002e60| 72 65 65 20 2a 74 72 65 | 65 29 0d 09 7b 0d 09 09 |ree *tre|e)..{...|
|00002e70| 6f 63 74 72 65 65 4e 6f | 64 65 20 2a 6e 6f 64 65 |octreeNo|de *node|
|00002e80| 20 3d 20 26 74 72 65 65 | 2d 3e 6e 6f 64 65 42 61 | = &tree|->nodeBa|
|00002e90| 73 65 5b 30 5d 3b 0d 09 | 09 73 68 6f 72 74 20 63 |se[0];..|.short c|
|00002ea0| 6f 75 6e 74 65 72 3b 0d | 0d 09 09 2b 2b 74 72 65 |ounter;.|...++tre|
|00002eb0| 65 2d 3e 76 61 6c 69 64 | 61 74 69 6f 6e 43 6f 75 |e->valid|ationCou|
|00002ec0| 6e 74 3b 0d 09 09 49 66 | 44 65 62 75 67 28 6e 6f |nt;...If|Debug(no|
|00002ed0| 64 65 2d 3e 63 68 69 6c | 64 72 65 6e 20 3d 3d 20 |de->chil|dren == |
|00002ee0| 6f 62 73 6f 6c 65 74 65 | 4e 6f 64 65 2c 20 22 5c |obsolete|Node, "\|
|00002ef0| 70 74 68 65 20 74 6f 70 | 20 6e 6f 64 65 20 63 61 |pthe top| node ca|
|00002f00| 6e 6e 6f 74 20 62 65 20 | 6f 62 73 6f 6c 65 74 65 |nnot be |obsolete|
|00002f10| 22 29 3b 0d 09 09 56 61 | 6c 69 64 61 74 65 4e 6f |");...Va|lidateNo|
|00002f20| 64 65 28 74 72 65 65 2c | 20 6e 6f 64 65 29 3b 0d |de(tree,| node);.|
|00002f30| 0d 09 09 63 6f 75 6e 74 | 65 72 20 3d 20 6d 61 78 |...count|er = max|
|00002f40| 69 6d 75 6d 4c 65 76 65 | 6c 20 2b 20 31 3b 0d 09 |imumLeve|l + 1;..|
|00002f50| 09 77 68 69 6c 65 28 20 | 2d 2d 63 6f 75 6e 74 65 |.while( |--counte|
|00002f60| 72 20 3e 20 30 20 29 0d | 09 09 09 56 61 6c 69 64 |r > 0 ).|...Valid|
|00002f70| 61 74 65 43 6f 6c 6f 72 | 4c 69 73 74 28 74 72 65 |ateColor|List(tre|
|00002f80| 65 2c 20 74 72 65 65 2d | 3e 63 6f 6c 6f 72 4c 69 |e, tree-|>colorLi|
|00002f90| 73 74 5b 63 6f 75 6e 74 | 65 72 5d 29 3b 0d 09 7d |st[count|er]);..}|
|00002fa0| 0d 23 65 6e 64 69 66 0d | 0d 0d 2f 2a 09 74 68 69 |.#endif.|../*.thi|
|00002fb0| 73 20 66 75 6e 63 74 69 | 6f 6e 20 69 73 20 63 61 |s functi|on is ca|
|00002fc0| 6c 6c 65 64 20 74 6f 20 | 61 64 64 20 65 61 63 68 |lled to |add each|
|00002fd0| 20 63 6f 6c 6f 72 20 74 | 6f 20 74 68 65 20 6f 63 | color t|o the oc|
|00002fe0| 74 72 65 65 20 2a 2f 0d | 0d 73 74 61 74 69 63 20 |tree */.|.static |
|00002ff0| 76 6f 69 64 20 41 64 64 | 43 6f 6c 6f 72 54 6f 4f |void Add|ColorToO|
|00003000| 63 74 72 65 65 28 6f 63 | 74 72 65 65 20 2a 74 72 |ctree(oc|tree *tr|
|00003010| 65 65 2c 20 52 47 42 43 | 6f 6c 6f 72 20 2a 69 6e |ee, RGBC|olor *in|
|00003020| 70 75 74 43 6f 6c 6f 72 | 29 0d 7b 0d 09 63 68 61 |putColor|).{..cha|
|00003030| 72 20 72 65 64 20 3d 20 | 69 6e 70 75 74 43 6f 6c |r red = |inputCol|
|00003040| 6f 72 2d 3e 72 65 64 20 | 3e 3e 20 38 3b 0d 09 63 |or->red |>> 8;..c|
|00003050| 68 61 72 20 67 72 65 65 | 6e 20 3d 20 69 6e 70 75 |har gree|n = inpu|
|00003060| 74 43 6f 6c 6f 72 2d 3e | 67 72 65 65 6e 20 3e 3e |tColor->|green >>|
|00003070| 20 38 3b 0d 09 63 68 61 | 72 20 62 6c 75 65 20 3d | 8;..cha|r blue =|
|00003080| 20 69 6e 70 75 74 43 6f | 6c 6f 72 2d 3e 62 6c 75 | inputCo|lor->blu|
|00003090| 65 20 3e 3e 20 38 3b 0d | 09 6f 63 74 72 65 65 4e |e >> 8;.|.octreeN|
|000030a0| 6f 64 65 20 2a 6e 6f 64 | 65 20 3d 20 26 74 72 65 |ode *nod|e = &tre|
|000030b0| 65 2d 3e 6e 6f 64 65 42 | 61 73 65 5b 30 5d 3b 0d |e->nodeB|ase[0];.|
|000030c0| 09 73 68 6f 72 74 20 6c | 65 76 65 6c 20 3d 20 30 |.short l|evel = 0|
|000030d0| 3b 0d 09 73 68 6f 72 74 | 20 69 6e 64 65 78 3b 0d |;..short| index;.|
|000030e0| 0d 09 56 61 6c 69 64 61 | 74 65 54 72 65 65 28 74 |..Valida|teTree(t|
|000030f0| 72 65 65 29 3b 0d 09 77 | 68 69 6c 65 28 20 74 72 |ree);..w|hile( tr|
|00003100| 75 65 20 29 20 7b 0d 09 | 09 73 68 6f 72 74 20 2a |ue ) {..|.short *|
|00003110| 63 68 69 6c 64 50 74 72 | 3b 0d 0d 09 09 2b 2b 6c |childPtr|;....++l|
|00003120| 65 76 65 6c 3b 0d 0d 09 | 2f 2a 09 75 73 65 20 74 |evel;...|/*.use t|
|00003130| 68 65 20 72 65 64 2c 20 | 67 72 65 65 6e 2c 20 61 |he red, |green, a|
|00003140| 6e 64 20 62 6c 75 65 20 | 69 6e 70 75 74 20 63 6f |nd blue |input co|
|00003150| 6d 70 6f 6e 65 6e 74 73 | 20 74 6f 20 64 65 74 65 |mponents| to dete|
|00003160| 72 6d 69 6e 65 20 77 68 | 69 63 68 20 6f 66 20 74 |rmine wh|ich of t|
|00003170| 68 65 20 65 69 67 68 74 | 20 63 68 69 6c 64 72 65 |he eight| childre|
|00003180| 6e 20 6f 66 20 74 68 69 | 73 20 6e 6f 64 65 20 74 |n of thi|s node t|
|00003190| 6f 20 6c 6f 6f 6b 0d 09 | 09 61 74 2e 20 74 68 65 |o look..|.at. the|
|000031a0| 6e 20 73 68 69 66 74 20 | 74 68 65 20 63 6f 6d 70 |n shift |the comp|
|000031b0| 6f 6e 65 6e 74 73 20 6c | 65 66 74 20 62 79 20 6f |onents l|eft by o|
|000031c0| 6e 65 20 62 69 74 20 74 | 6f 20 6c 65 61 76 65 20 |ne bit t|o leave |
|000031d0| 74 68 65 6d 20 73 65 74 | 75 70 20 66 6f 72 20 74 |them set|up for t|
|000031e0| 68 65 20 6e 65 78 74 20 | 74 69 6d 65 20 74 68 72 |he next |time thr|
|000031f0| 6f 75 67 68 20 74 68 69 | 73 20 6c 6f 6f 70 2e 20 |ough thi|s loop. |
|00003200| 2a 2f 0d 0d 09 09 69 6e | 64 65 78 20 3d 20 30 3b |*/....in|dex = 0;|
|00003210| 0d 09 09 69 66 28 72 65 | 64 20 3c 20 30 29 09 09 |...if(re|d < 0)..|
|00003220| 69 6e 64 65 78 20 2b 3d | 20 34 3b 09 72 65 64 20 |index +=| 4;.red |
|00003230| 3c 3c 3d 20 31 3b 0d 09 | 09 69 66 28 67 72 65 65 |<<= 1;..|.if(gree|
|00003240| 6e 20 3c 20 30 29 09 69 | 6e 64 65 78 20 2b 3d 20 |n < 0).i|ndex += |
|00003250| 32 3b 09 67 72 65 65 6e | 20 3c 3c 3d 20 31 3b 0d |2;.green| <<= 1;.|
|00003260| 09 09 69 66 28 62 6c 75 | 65 20 3c 20 30 29 09 69 |..if(blu|e < 0).i|
|00003270| 6e 64 65 78 20 2b 3d 20 | 31 3b 09 62 6c 75 65 20 |ndex += |1;.blue |
|00003280| 3c 3c 3d 20 31 3b 0d 0d | 09 2f 2a 09 67 65 74 20 |<<= 1;..|./*.get |
|00003290| 61 20 70 6f 69 6e 74 65 | 72 20 74 6f 20 74 68 65 |a pointe|r to the|
|000032a0| 20 63 68 69 6c 64 20 69 | 6e 20 74 68 69 73 20 6e | child i|n this n|
|000032b0| 6f 64 65 20 74 68 61 74 | 20 77 65 20 61 72 65 20 |ode that| we are |
|000032c0| 67 6f 69 6e 67 20 74 6f | 20 6c 6f 6f 6b 20 61 74 |going to| look at|
|000032d0| 2e 20 2a 2f 0d 0d 09 09 | 63 68 69 6c 64 50 74 72 |. */....|childPtr|
|000032e0| 20 3d 20 26 6e 6f 64 65 | 2d 3e 6c 65 61 66 5b 69 | = &node|->leaf[i|
|000032f0| 6e 64 65 78 5d 3b 0d 09 | 09 69 6e 64 65 78 20 3d |ndex];..|.index =|
|00003300| 20 2a 63 68 69 6c 64 50 | 74 72 3b 0d 0d 09 09 69 | *childP|tr;....i|
|00003310| 66 28 20 69 6e 64 65 78 | 20 3d 3d 20 65 6d 70 74 |f( index| == empt|
|00003320| 79 4e 6f 64 65 20 29 20 | 7b 0d 0d 09 09 09 2f 2a |yNode ) |{...../*|
|00003330| 20 69 6e 63 72 65 6d 65 | 6e 74 20 74 68 69 73 20 | increme|nt this |
|00003340| 6e 6f 64 65 d5 73 20 63 | 68 69 6c 64 20 63 6f 75 |node.s c|hild cou|
|00003350| 6e 74 2c 20 73 69 6e 63 | 65 20 69 74 20 6e 6f 77 |nt, sinc|e it now|
|00003360| 20 68 61 73 20 63 68 69 | 6c 64 72 65 6e 2e 20 74 | has chi|ldren. t|
|00003370| 68 65 6e 20 63 61 6c 63 | 75 6c 61 74 65 20 74 68 |hen calc|ulate th|
|00003380| 65 20 69 6e 64 65 78 20 | 6f 66 20 74 68 65 20 70 |e index |of the p|
|00003390| 61 72 65 6e 74 20 6e 6f | 64 65 20 2a 2f 0d 09 09 |arent no|de */...|
|000033a0| 09 2b 2b 6e 6f 64 65 2d | 3e 63 68 69 6c 64 72 65 |.++node-|>childre|
|000033b0| 6e 3b 0d 09 09 09 69 6e | 64 65 78 20 3d 20 6e 6f |n;....in|dex = no|
|000033c0| 64 65 20 2d 20 26 74 72 | 65 65 2d 3e 6e 6f 64 65 |de - &tr|ee->node|
|000033d0| 42 61 73 65 5b 30 5d 3b | 0d 0d 09 09 09 69 66 28 |Base[0];|.....if(|
|000033e0| 20 6c 65 76 65 6c 20 3d | 3d 20 6d 61 78 69 6d 75 | level =|= maximu|
|000033f0| 6d 4c 65 76 65 6c 20 29 | 20 7b 0d 09 09 09 09 6f |mLevel )| {.....o|
|00003400| 63 74 72 65 65 43 6f 6c | 6f 72 20 2a 63 6f 6c 6f |ctreeCol|or *colo|
|00003410| 72 3b 0d 0d 09 09 09 09 | 49 66 44 65 62 75 67 28 |r;......|IfDebug(|
|00003420| 74 72 65 65 2d 3e 63 6f | 6c 6f 72 73 20 3e 3d 20 |tree->co|lors >= |
|00003430| 74 72 65 65 2d 3e 6d 61 | 78 69 6d 75 6d 43 6f 6c |tree->ma|ximumCol|
|00003440| 6f 72 73 2c 20 22 5c 70 | 6e 6f 20 72 6f 6f 6d 20 |ors, "\p|no room |
|00003450| 74 6f 20 63 72 65 61 74 | 65 20 61 6e 6f 74 68 65 |to creat|e anothe|
|00003460| 72 20 63 6f 6c 6f 72 22 | 29 3b 0d 0d 09 09 09 2f |r color"|);...../|
|00003470| 2a 09 74 68 65 20 63 68 | 69 6c 64 20 61 74 20 74 |*.the ch|ild at t|
|00003480| 68 69 73 20 70 6f 73 69 | 74 69 6f 6e 20 77 61 73 |his posi|tion was|
|00003490| 20 65 6d 70 74 79 20 61 | 6e 64 20 77 65 20 61 72 | empty a|nd we ar|
|000034a0| 65 20 61 74 20 6c 65 76 | 65 6c 20 65 69 67 68 74 |e at lev|el eight|
|000034b0| 20 28 74 68 65 20 64 65 | 65 70 65 73 74 20 70 6f | (the de|epest po|
|000034c0| 73 73 69 62 6c 65 29 2c | 20 73 6f 20 61 64 64 20 |ssible),| so add |
|000034d0| 74 68 65 20 69 6e 70 75 | 74 0d 09 09 09 09 63 6f |the inpu|t.....co|
|000034e0| 6c 6f 72 20 74 6f 20 74 | 68 65 20 63 6f 6c 6f 72 |lor to t|he color|
|000034f0| 20 74 61 62 6c 65 20 61 | 6e 64 20 73 65 74 20 74 | table a|nd set t|
|00003500| 68 69 73 20 63 68 69 6c | 64 20 74 6f 20 d2 70 6f |his chil|d to .po|
|00003510| 69 6e 74 d3 20 74 6f 20 | 74 68 69 73 20 6e 65 77 |int. to |this new|
|00003520| 20 63 6f 6c 6f 72 20 65 | 6e 74 72 79 2e 20 6e 6f | color e|ntry. no|
|00003530| 74 65 20 74 68 61 74 20 | 69 6e 64 69 63 65 73 20 |te that |indices |
|00003540| 74 68 61 74 0d 09 09 09 | 09 70 6f 69 6e 74 20 74 |that....|.point t|
|00003550| 6f 20 65 6e 74 72 69 65 | 73 20 69 6e 20 74 68 65 |o entrie|s in the|
|00003560| 20 63 6f 6c 6f 72 20 74 | 61 62 6c 65 20 61 72 65 | color t|able are|
|00003570| 20 6e 65 67 61 74 69 76 | 65 20 74 6f 20 64 69 73 | negativ|e to dis|
|00003580| 74 69 6e 67 75 69 73 68 | 20 74 68 65 6d 20 66 72 |tinguish| them fr|
|00003590| 6f 6d 20 69 6e 64 69 63 | 65 73 20 74 68 61 74 20 |om indic|es that |
|000035a0| 70 6f 69 6e 74 20 74 6f | 20 65 6e 74 72 69 65 73 |point to| entries|
|000035b0| 0d 09 09 09 09 69 6e 20 | 74 68 65 20 6e 6f 64 65 |.....in |the node|
|000035c0| 20 74 61 62 6c 65 2e 20 | 2a 2f 0d 0d 09 09 09 09 | table. |*/......|
|000035d0| 2a 63 68 69 6c 64 50 74 | 72 20 3d 20 7e 74 72 65 |*childPt|r = ~tre|
|000035e0| 65 2d 3e 63 6f 6c 6f 72 | 73 3b 0d 09 09 09 09 63 |e->color|s;.....c|
|000035f0| 6f 6c 6f 72 20 3d 20 26 | 74 72 65 65 2d 3e 63 6f |olor = &|tree->co|
|00003600| 6c 6f 72 42 61 73 65 5b | 74 72 65 65 2d 3e 63 6f |lorBase[|tree->co|
|00003610| 6c 6f 72 73 5d 3b 0d 09 | 09 09 09 63 6f 6c 6f 72 |lors];..|...color|
|00003620| 2d 3e 63 6f 75 6e 74 20 | 3d 20 31 3b 0d 09 09 09 |->count |= 1;....|
|00003630| 09 63 6f 6c 6f 72 2d 3e | 74 6f 74 61 6c 52 65 64 |.color->|totalRed|
|00003640| 20 3d 20 69 6e 70 75 74 | 43 6f 6c 6f 72 2d 3e 72 | = input|Color->r|
|00003650| 65 64 3b 0d 09 09 09 09 | 63 6f 6c 6f 72 2d 3e 74 |ed;.....|color->t|
|00003660| 6f 74 61 6c 47 72 65 65 | 6e 20 3d 20 69 6e 70 75 |otalGree|n = inpu|
|00003670| 74 43 6f 6c 6f 72 2d 3e | 67 72 65 65 6e 3b 0d 09 |tColor->|green;..|
|00003680| 09 09 09 63 6f 6c 6f 72 | 2d 3e 74 6f 74 61 6c 42 |...color|->totalB|
|00003690| 6c 75 65 20 3d 20 69 6e | 70 75 74 43 6f 6c 6f 72 |lue = in|putColor|
|000036a0| 2d 3e 62 6c 75 65 3b 0d | 0d 09 09 09 09 63 6f 6c |->blue;.|.....col|
|000036b0| 6f 72 2d 3e 6c 65 76 65 | 6c 20 3d 20 6c 65 76 65 |or->leve|l = leve|
|000036c0| 6c 3b 0d 09 09 09 09 63 | 6f 6c 6f 72 2d 3e 6e 65 |l;.....c|olor->ne|
|000036d0| 78 74 20 3d 20 74 72 65 | 65 2d 3e 63 6f 6c 6f 72 |xt = tre|e->color|
|000036e0| 4c 69 73 74 5b 6c 65 76 | 65 6c 5d 3b 0d 09 09 09 |List[lev|el];....|
|000036f0| 09 63 6f 6c 6f 72 2d 3e | 70 61 72 65 6e 74 20 3d |.color->|parent =|
|00003700| 20 69 6e 64 65 78 3b 0d | 09 09 09 09 74 72 65 65 | index;.|....tree|
|00003710| 2d 3e 63 6f 6c 6f 72 4c | 69 73 74 5b 6c 65 76 65 |->colorL|ist[leve|
|00003720| 6c 5d 20 3d 20 74 72 65 | 65 2d 3e 63 6f 6c 6f 72 |l] = tre|e->color|
|00003730| 73 3b 0d 09 09 09 09 2b | 2b 74 72 65 65 2d 3e 63 |s;.....+|+tree->c|
|00003740| 6f 6c 6f 72 73 3b 0d 09 | 09 09 09 72 65 74 75 72 |olors;..|...retur|
|00003750| 6e 3b 0d 09 09 09 7d 0d | 0d 09 09 09 49 66 44 65 |n;....}.|....IfDe|
|00003760| 62 75 67 28 74 72 65 65 | 2d 3e 6e 6f 64 65 73 20 |bug(tree|->nodes |
|00003770| 3e 3d 20 74 72 65 65 2d | 3e 6d 61 78 69 6d 75 6d |>= tree-|>maximum|
|00003780| 4e 6f 64 65 73 2c 20 22 | 5c 70 6e 6f 20 72 6f 6f |Nodes, "|\pno roo|
|00003790| 6d 20 74 6f 20 63 72 65 | 61 74 65 20 61 6e 6f 74 |m to cre|ate anot|
|000037a0| 68 65 72 20 6e 6f 64 65 | 22 29 3b 0d 0d 09 09 2f |her node|");..../|
|000037b0| 2a 09 63 72 65 61 74 65 | 20 61 20 6e 65 77 20 6e |*.create| a new n|
|000037c0| 6f 64 65 20 68 65 72 65 | 20 61 6e 64 20 73 65 74 |ode here| and set|
|000037d0| 20 74 68 69 73 20 63 68 | 69 6c 64 20 74 6f 20 d2 | this ch|ild to .|
|000037e0| 70 6f 69 6e 74 d3 20 74 | 6f 20 74 68 69 73 20 6e |point. t|o this n|
|000037f0| 65 77 20 63 6f 6c 6f 72 | 20 65 6e 74 72 79 2e 20 |ew color| entry. |
|00003800| 6e 65 78 74 20 63 6c 65 | 61 72 20 61 6c 6c 20 74 |next cle|ar all t|
|00003810| 68 65 20 66 69 65 6c 64 | 73 20 6f 66 0d 09 09 09 |he field|s of....|
|00003820| 74 68 65 20 6e 65 77 20 | 6e 6f 64 65 2e 20 2a 2f |the new |node. */|
|00003830| 0d 0d 09 09 09 2a 63 68 | 69 6c 64 50 74 72 20 3d |.....*ch|ildPtr =|
|00003840| 20 74 72 65 65 2d 3e 6e | 6f 64 65 73 3b 0d 09 09 | tree->n|odes;...|
|00003850| 09 6e 6f 64 65 20 3d 20 | 26 74 72 65 65 2d 3e 6e |.node = |&tree->n|
|00003860| 6f 64 65 42 61 73 65 5b | 74 72 65 65 2d 3e 6e 6f |odeBase[|tree->no|
|00003870| 64 65 73 5d 3b 0d 09 09 | 09 6e 6f 64 65 2d 3e 63 |des];...|.node->c|
|00003880| 68 69 6c 64 72 65 6e 20 | 3d 20 30 3b 0d 09 09 09 |hildren |= 0;....|
|00003890| 6e 6f 64 65 2d 3e 70 61 | 72 65 6e 74 20 3d 20 69 |node->pa|rent = i|
|000038a0| 6e 64 65 78 3b 0d 09 09 | 09 6e 6f 64 65 2d 3e 6c |ndex;...|.node->l|
|000038b0| 65 61 66 5b 30 5d 20 3d | 20 65 6d 70 74 79 4e 6f |eaf[0] =| emptyNo|
|000038c0| 64 65 3b 0d 09 09 09 6e | 6f 64 65 2d 3e 6c 65 61 |de;....n|ode->lea|
|000038d0| 66 5b 31 5d 20 3d 20 65 | 6d 70 74 79 4e 6f 64 65 |f[1] = e|mptyNode|
|000038e0| 3b 0d 09 09 09 6e 6f 64 | 65 2d 3e 6c 65 61 66 5b |;....nod|e->leaf[|
|000038f0| 32 5d 20 3d 20 65 6d 70 | 74 79 4e 6f 64 65 3b 0d |2] = emp|tyNode;.|
|00003900| 09 09 09 6e 6f 64 65 2d | 3e 6c 65 61 66 5b 33 5d |...node-|>leaf[3]|
|00003910| 20 3d 20 65 6d 70 74 79 | 4e 6f 64 65 3b 0d 09 09 | = empty|Node;...|
|00003920| 09 6e 6f 64 65 2d 3e 6c | 65 61 66 5b 34 5d 20 3d |.node->l|eaf[4] =|
|00003930| 20 65 6d 70 74 79 4e 6f | 64 65 3b 0d 09 09 09 6e | emptyNo|de;....n|
|00003940| 6f 64 65 2d 3e 6c 65 61 | 66 5b 35 5d 20 3d 20 65 |ode->lea|f[5] = e|
|00003950| 6d 70 74 79 4e 6f 64 65 | 3b 0d 09 09 09 6e 6f 64 |mptyNode|;....nod|
|00003960| 65 2d 3e 6c 65 61 66 5b | 36 5d 20 3d 20 65 6d 70 |e->leaf[|6] = emp|
|00003970| 74 79 4e 6f 64 65 3b 0d | 09 09 09 6e 6f 64 65 2d |tyNode;.|...node-|
|00003980| 3e 6c 65 61 66 5b 37 5d | 20 3d 20 65 6d 70 74 79 |>leaf[7]| = empty|
|00003990| 4e 6f 64 65 3b 0d 09 09 | 09 2b 2b 74 72 65 65 2d |Node;...|.++tree-|
|000039a0| 3e 6e 6f 64 65 73 3b 0d | 09 09 09 63 6f 6e 74 69 |>nodes;.|...conti|
|000039b0| 6e 75 65 3b 0d 0d 09 09 | 7d 20 65 6c 73 65 20 69 |nue;....|} else i|
|000039c0| 66 28 20 69 6e 64 65 78 | 20 3c 20 30 20 29 20 7b |f( index| < 0 ) {|
|000039d0| 0d 09 09 09 6f 63 74 72 | 65 65 43 6f 6c 6f 72 20 |....octr|eeColor |
|000039e0| 2a 63 6f 6c 6f 72 20 3d | 20 26 74 72 65 65 2d 3e |*color =| &tree->|
|000039f0| 63 6f 6c 6f 72 42 61 73 | 65 5b 7e 69 6e 64 65 78 |colorBas|e[~index|
|00003a00| 5d 3b 0d 0d 09 09 2f 2a | 09 74 68 65 20 63 68 69 |];..../*|.the chi|
|00003a10| 6c 64 20 61 74 20 74 68 | 69 73 20 70 6f 73 69 74 |ld at th|is posit|
|00003a20| 69 6f 6e 20 77 61 73 20 | 61 20 63 6f 6c 6f 72 20 |ion was |a color |
|00003a30| 73 6f 20 61 64 64 20 74 | 68 65 20 69 6e 70 75 74 |so add t|he input|
|00003a40| 20 63 6f 6c 6f 72 20 74 | 6f 20 74 68 65 20 74 6f | color t|o the to|
|00003a50| 74 61 6c 20 63 6f 6c 6f | 72 20 66 6f 72 20 74 68 |tal colo|r for th|
|00003a60| 69 73 20 65 6e 74 72 79 | 20 61 6e 64 20 69 6e 63 |is entry| and inc|
|00003a70| 72 65 6d 65 6e 74 0d 09 | 09 09 74 68 65 20 63 6f |rement..|..the co|
|00003a80| 75 6e 74 2e 20 77 65 20 | 63 61 6e 20 75 73 65 20 |unt. we |can use |
|00003a90| 74 68 65 73 65 20 76 61 | 6c 75 65 73 20 61 74 20 |these va|lues at |
|00003aa0| 74 68 65 20 65 6e 64 20 | 6f 66 20 74 68 65 20 70 |the end |of the p|
|00003ab0| 72 6f 63 65 73 73 20 74 | 6f 20 63 61 6c 63 75 6c |rocess t|o calcul|
|00003ac0| 61 74 65 20 61 6e 20 61 | 76 65 72 61 67 65 20 63 |ate an a|verage c|
|00003ad0| 6f 6c 6f 72 20 66 6f 72 | 20 74 68 69 73 20 65 6e |olor for| this en|
|00003ae0| 74 72 79 2e 0d 09 09 09 | 6e 6f 74 65 20 74 68 61 |try.....|note tha|
|00003af0| 74 20 74 68 65 73 65 20 | 74 6f 74 61 6c 73 20 77 |t these |totals w|
|00003b00| 69 6c 6c 20 6f 76 65 72 | 66 6c 6f 77 20 77 68 65 |ill over|flow whe|
|00003b10| 6e 20 6d 6f 72 65 20 74 | 68 61 6e 20 36 35 35 33 |n more t|han 6553|
|00003b20| 36 20 70 69 78 65 6c 73 | 20 77 69 74 68 20 6c 61 |6 pixels| with la|
|00003b30| 72 67 65 20 63 6f 6d 70 | 6f 6e 65 6e 74 73 20 28 |rge comp|onents (|
|00003b40| 67 72 65 61 74 65 72 20 | 74 68 61 6e 0d 09 09 09 |greater |than....|
|00003b50| 36 35 30 30 30 29 20 61 | 72 65 20 61 6c 6c 20 69 |65000) a|re all i|
|00003b60| 6e 20 74 68 69 73 20 62 | 6f 78 3b 20 77 65 20 61 |n this b|ox; we a|
|00003b70| 72 65 6e d5 74 20 67 6f | 69 6e 67 20 74 6f 20 77 |ren.t go|ing to w|
|00003b80| 6f 72 72 79 20 61 62 6f | 75 74 20 74 68 69 73 2c |orry abo|ut this,|
|00003b90| 20 66 6f 72 20 6e 6f 77 | 2e 20 2a 2f 0d 0d 09 09 | for now|. */....|
|00003ba0| 09 2b 2b 63 6f 6c 6f 72 | 2d 3e 63 6f 75 6e 74 3b |.++color|->count;|
|00003bb0| 0d 09 09 09 63 6f 6c 6f | 72 2d 3e 74 6f 74 61 6c |....colo|r->total|
|00003bc0| 52 65 64 20 2b 3d 20 69 | 6e 70 75 74 43 6f 6c 6f |Red += i|nputColo|
|00003bd0| 72 2d 3e 72 65 64 3b 0d | 09 09 09 63 6f 6c 6f 72 |r->red;.|...color|
|00003be0| 2d 3e 74 6f 74 61 6c 47 | 72 65 65 6e 20 2b 3d 20 |->totalG|reen += |
|00003bf0| 69 6e 70 75 74 43 6f 6c | 6f 72 2d 3e 67 72 65 65 |inputCol|or->gree|
|00003c00| 6e 3b 0d 09 09 09 63 6f | 6c 6f 72 2d 3e 74 6f 74 |n;....co|lor->tot|
|00003c10| 61 6c 42 6c 75 65 20 2b | 3d 20 69 6e 70 75 74 43 |alBlue +|= inputC|
|00003c20| 6f 6c 6f 72 2d 3e 62 6c | 75 65 3b 0d 09 09 09 72 |olor->bl|ue;....r|
|00003c30| 65 74 75 72 6e 3b 0d 09 | 09 7d 0d 0d 09 09 49 66 |eturn;..|.}....If|
|00003c40| 44 65 62 75 67 28 69 6e | 64 65 78 20 3e 3d 20 74 |Debug(in|dex >= t|
|00003c50| 72 65 65 2d 3e 6e 6f 64 | 65 73 2c 20 22 5c 70 70 |ree->nod|es, "\pp|
|00003c60| 61 73 74 20 74 68 65 20 | 65 6e 64 20 6f 66 20 74 |ast the |end of t|
|00003c70| 68 65 20 6f 63 74 72 65 | 65 22 29 3b 0d 09 09 6e |he octre|e");...n|
|00003c80| 6f 64 65 20 3d 20 26 74 | 72 65 65 2d 3e 6e 6f 64 |ode = &t|ree->nod|
|00003c90| 65 42 61 73 65 5b 69 6e | 64 65 78 5d 3b 0d 09 7d |eBase[in|dex];..}|
|00003ca0| 0d 7d 0d 0d 0d 73 74 61 | 74 69 63 20 76 6f 69 64 |.}...sta|tic void|
|00003cb0| 20 52 65 6d 6f 76 65 43 | 6f 6c 6f 72 46 72 6f 6d | RemoveC|olorFrom|
|00003cc0| 4c 65 76 65 6c 28 6f 63 | 74 72 65 65 20 2a 74 72 |Level(oc|tree *tr|
|00003cd0| 65 65 2c 20 73 68 6f 72 | 74 20 63 6f 6c 6f 72 49 |ee, shor|t colorI|
|00003ce0| 6e 64 65 78 29 0d 7b 0d | 09 6f 63 74 72 65 65 43 |ndex).{.|.octreeC|
|00003cf0| 6f 6c 6f 72 20 2a 63 6f | 6c 6f 72 20 3d 20 26 74 |olor *co|lor = &t|
|00003d00| 72 65 65 2d 3e 63 6f 6c | 6f 72 42 61 73 65 5b 63 |ree->col|orBase[c|
|00003d10| 6f 6c 6f 72 49 6e 64 65 | 78 5d 3b 0d 0d 09 49 66 |olorInde|x];...If|
|00003d20| 44 65 62 75 67 28 63 6f | 6c 6f 72 49 6e 64 65 78 |Debug(co|lorIndex|
|00003d30| 20 3e 3d 20 74 72 65 65 | 2d 3e 63 6f 6c 6f 72 73 | >= tree|->colors|
|00003d40| 2c 20 22 5c 70 63 6f 6c | 6f 72 20 74 6f 20 72 65 |, "\pcol|or to re|
|00003d50| 6d 6f 76 65 20 64 6f 65 | 73 6e 74 20 65 78 69 73 |move doe|snt exis|
|00003d60| 74 22 29 3b 0d 0d 09 69 | 66 28 20 74 72 65 65 2d |t");...i|f( tree-|
|00003d70| 3e 63 6f 6c 6f 72 4c 69 | 73 74 5b 63 6f 6c 6f 72 |>colorLi|st[color|
|00003d80| 2d 3e 6c 65 76 65 6c 5d | 20 3d 3d 20 63 6f 6c 6f |->level]| == colo|
|00003d90| 72 49 6e 64 65 78 20 29 | 0d 09 09 74 72 65 65 2d |rIndex )|...tree-|
|00003da0| 3e 63 6f 6c 6f 72 4c 69 | 73 74 5b 63 6f 6c 6f 72 |>colorLi|st[color|
|00003db0| 2d 3e 6c 65 76 65 6c 5d | 20 3d 20 63 6f 6c 6f 72 |->level]| = color|
|00003dc0| 2d 3e 6e 65 78 74 3b 0d | 09 65 6c 73 65 20 7b 0d |->next;.|.else {.|
|00003dd0| 09 09 73 68 6f 72 74 20 | 69 6e 64 65 78 20 3d 20 |..short |index = |
|00003de0| 74 72 65 65 2d 3e 63 6f | 6c 6f 72 4c 69 73 74 5b |tree->co|lorList[|
|00003df0| 63 6f 6c 6f 72 2d 3e 6c | 65 76 65 6c 5d 3b 0d 0d |color->l|evel];..|
|00003e00| 09 09 77 68 69 6c 65 28 | 20 69 6e 64 65 78 20 21 |..while(| index !|
|00003e10| 3d 20 65 6d 70 74 79 4e | 6f 64 65 20 29 20 7b 0d |= emptyN|ode ) {.|
|00003e20| 09 09 09 63 6f 6c 6f 72 | 20 3d 20 26 74 72 65 65 |...color| = &tree|
|00003e30| 2d 3e 63 6f 6c 6f 72 42 | 61 73 65 5b 69 6e 64 65 |->colorB|ase[inde|
|00003e40| 78 5d 3b 0d 09 09 09 49 | 66 44 65 62 75 67 28 69 |x];....I|fDebug(i|
|00003e50| 6e 64 65 78 20 3e 3d 20 | 74 72 65 65 2d 3e 63 6f |ndex >= |tree->co|
|00003e60| 6c 6f 72 73 2c 20 22 5c | 70 63 6f 6c 6f 72 20 69 |lors, "\|pcolor i|
|00003e70| 6e 20 63 6f 6c 6f 72 20 | 6c 69 73 74 20 64 6f 65 |n color |list doe|
|00003e80| 73 6e 74 20 65 78 69 73 | 74 22 29 3b 0d 09 09 09 |snt exis|t");....|
|00003e90| 69 66 28 20 63 6f 6c 6f | 72 2d 3e 6e 65 78 74 20 |if( colo|r->next |
|00003ea0| 3d 3d 20 63 6f 6c 6f 72 | 49 6e 64 65 78 20 29 20 |== color|Index ) |
|00003eb0| 7b 0d 09 09 09 09 63 6f | 6c 6f 72 2d 3e 6e 65 78 |{.....co|lor->nex|
|00003ec0| 74 20 3d 20 74 72 65 65 | 2d 3e 63 6f 6c 6f 72 42 |t = tree|->colorB|
|00003ed0| 61 73 65 5b 63 6f 6c 6f | 72 2d 3e 6e 65 78 74 5d |ase[colo|r->next]|
|00003ee0| 2e 6e 65 78 74 3b 0d 09 | 09 09 09 72 65 74 75 72 |.next;..|...retur|
|00003ef0| 6e 3b 0d 09 09 09 7d 0d | 09 09 09 69 6e 64 65 78 |n;....}.|...index|
|00003f00| 20 3d 20 63 6f 6c 6f 72 | 2d 3e 6e 65 78 74 3b 0d | = color|->next;.|
|00003f10| 09 09 7d 0d 0d 09 09 49 | 66 44 65 62 75 67 28 31 |..}....I|fDebug(1|
|00003f20| 2c 20 22 5c 70 63 6f 6c | 6f 72 20 74 6f 20 72 65 |, "\pcol|or to re|
|00003f30| 6d 6f 76 65 20 69 73 20 | 6e 6f 74 20 69 6e 20 74 |move is |not in t|
|00003f40| 68 69 73 20 6c 65 76 65 | 6c 20 6c 69 73 74 22 29 |his leve|l list")|
|00003f50| 3b 0d 09 7d 0d 7d 0d 0d | 0d 2f 2a 09 74 68 69 73 |;..}.}..|./*.this|
|00003f60| 20 66 75 6e 63 74 69 6f | 6e 20 72 65 6d 6f 76 65 | functio|n remove|
|00003f70| 73 20 74 68 65 20 63 6f | 6c 6f 72 20 73 70 65 63 |s the co|lor spec|
|00003f80| 69 66 69 65 64 20 62 79 | 20 6e 65 77 49 6e 64 65 |ified by| newInde|
|00003f90| 78 20 66 72 6f 6d 20 74 | 68 65 20 6f 63 74 72 65 |x from t|he octre|
|00003fa0| 65 2e 20 73 69 6e 63 65 | 20 74 68 65 20 63 6f 6c |e. since| the col|
|00003fb0| 6f 72 20 74 61 62 6c 65 | 20 69 6e 20 74 68 65 20 |or table| in the |
|00003fc0| 6f 63 74 72 65 65 20 63 | 61 6e 6e 6f 74 20 68 61 |octree c|annot ha|
|00003fd0| 76 65 0d 09 67 61 70 73 | 2c 20 72 65 6d 6f 76 69 |ve..gaps|, removi|
|00003fe0| 6e 67 20 74 68 69 73 20 | 63 6f 6c 6f 72 20 72 65 |ng this |color re|
|00003ff0| 61 6c 6c 79 20 63 6f 6e | 73 69 73 74 73 20 6f 66 |ally con|sists of|
|00004000| 20 6d 6f 76 69 6e 67 20 | 74 68 65 20 6c 61 73 74 | moving |the last|
|00004010| 20 63 6f 6c 6f 72 20 69 | 6e 20 74 68 65 20 6f 63 | color i|n the oc|
|00004020| 74 72 65 65 20 74 6f 20 | 74 68 65 20 70 6f 73 69 |tree to |the posi|
|00004030| 74 69 6f 6e 20 6f 63 63 | 75 70 69 65 64 20 62 79 |tion occ|upied by|
|00004040| 20 6e 65 77 49 6e 64 65 | 78 0d 09 61 6e 64 20 74 | newInde|x..and t|
|00004050| 68 65 6e 20 72 65 64 75 | 63 69 6e 67 20 74 68 65 |hen redu|cing the|
|00004060| 20 74 6f 74 61 6c 20 63 | 6f 6c 6f 72 20 63 6f 75 | total c|olor cou|
|00004070| 6e 74 2e 20 73 69 6e 63 | 65 20 74 68 65 20 6e 6f |nt. sinc|e the no|
|00004080| 64 65 73 20 69 6e 20 74 | 68 65 20 6f 63 74 72 65 |des in t|he octre|
|00004090| 65 20 72 65 66 65 72 65 | 6e 63 65 20 74 68 69 73 |e refere|nce this|
|000040a0| 20 6c 61 73 74 20 63 6f | 6c 6f 72 20 6f 6e 63 65 | last co|lor once|
|000040b0| 20 73 6f 6d 65 77 68 65 | 72 65 2c 20 77 65 0d 09 | somewhe|re, we..|
|000040c0| 6d 75 73 74 20 73 63 61 | 6e 20 74 68 72 6f 75 67 |must sca|n throug|
|000040d0| 68 20 61 6c 6c 20 74 68 | 65 20 6e 6f 64 65 73 20 |h all th|e nodes |
|000040e0| 75 6e 74 69 6c 20 77 65 | 20 66 69 6e 64 20 74 68 |until we| find th|
|000040f0| 65 20 6f 6e 65 20 74 68 | 61 74 20 64 6f 65 73 20 |e one th|at does |
|00004100| 72 65 66 65 72 65 6e 63 | 65 20 69 74 20 61 6e 64 |referenc|e it and|
|00004110| 20 75 70 64 61 74 65 20 | 69 74 73 20 6c 65 61 66 | update |its leaf|
|00004120| 20 65 6e 74 72 79 20 74 | 6f 20 69 6e 64 65 78 20 | entry t|o index |
|00004130| 74 6f 20 74 68 65 0d 09 | 6e 65 77 20 70 6f 73 69 |to the..|new posi|
|00004140| 74 69 6f 6e 20 6f 66 20 | 74 68 69 73 20 63 6f 6c |tion of |this col|
|00004150| 6f 72 2e 20 74 68 69 73 | 20 66 75 6e 63 74 69 6f |or. this| functio|
|00004160| 6e 20 61 6c 73 6f 20 6b | 65 65 70 73 20 74 72 61 |n also k|eeps tra|
|00004170| 63 6b 20 6f 66 20 77 68 | 65 72 65 20 74 68 65 20 |ck of wh|ere the |
|00004180| 63 6f 6c 6f 72 20 70 6f | 69 6e 74 65 64 20 74 6f |color po|inted to|
|00004190| 20 62 79 20 70 72 65 73 | 65 72 76 65 43 6f 6c 6f | by pres|erveColo|
|000041a0| 72 20 6d 6f 76 65 73 20 | 74 6f 0d 09 28 69 66 20 |r moves |to..(if |
|000041b0| 69 74 20 64 6f 65 73 20 | 6d 6f 76 65 29 20 61 6e |it does |move) an|
|000041c0| 64 20 69 74 20 72 65 74 | 75 72 6e 73 20 74 68 69 |d it ret|urns thi|
|000041d0| 73 20 6e 65 77 20 6c 6f | 63 61 74 69 6f 6e 2e 20 |s new lo|cation. |
|000041e0| 2a 2f 0d 0d 73 74 61 74 | 69 63 20 6f 63 74 72 65 |*/..stat|ic octre|
|000041f0| 65 43 6f 6c 6f 72 20 2a | 52 65 6d 6f 76 65 43 6f |eColor *|RemoveCo|
|00004200| 6c 6f 72 28 6f 63 74 72 | 65 65 20 2a 74 72 65 65 |lor(octr|ee *tree|
|00004210| 2c 20 73 68 6f 72 74 20 | 6e 65 77 49 6e 64 65 78 |, short |newIndex|
|00004220| 2c 20 6f 63 74 72 65 65 | 43 6f 6c 6f 72 20 2a 70 |, octree|Color *p|
|00004230| 72 65 73 65 72 76 65 43 | 6f 6c 6f 72 29 0d 7b 0d |reserveC|olor).{.|
|00004240| 09 73 68 6f 72 74 20 6f | 6c 64 49 6e 64 65 78 3b |.short o|ldIndex;|
|00004250| 0d 0d 09 56 61 6c 69 64 | 61 74 65 54 72 65 65 28 |...Valid|ateTree(|
|00004260| 74 72 65 65 29 3b 0d 09 | 52 65 6d 6f 76 65 43 6f |tree);..|RemoveCo|
|00004270| 6c 6f 72 46 72 6f 6d 4c | 65 76 65 6c 28 74 72 65 |lorFromL|evel(tre|
|00004280| 65 2c 20 6e 65 77 49 6e | 64 65 78 29 3b 0d 0d 2f |e, newIn|dex);../|
|00004290| 2a 09 69 66 20 77 65 20 | 61 72 65 20 72 65 6d 6f |*.if we |are remo|
|000042a0| 76 69 6e 67 20 74 68 65 | 20 6c 61 73 74 20 63 6f |ving the| last co|
|000042b0| 6c 6f 72 2c 20 74 68 65 | 6e 20 74 68 65 72 65 20 |lor, the|n there |
|000042c0| 69 73 20 6e 6f 20 72 65 | 6f 72 64 65 72 69 6e 67 |is no re|ordering|
|000042d0| 20 74 6f 20 64 6f 2c 20 | 73 6f 20 73 69 6d 70 6c | to do, |so simpl|
|000042e0| 79 20 72 65 74 75 72 6e | 2e 20 2a 2f 0d 0d 09 6f |y return|. */...o|
|000042f0| 6c 64 49 6e 64 65 78 20 | 3d 20 2d 2d 74 72 65 65 |ldIndex |= --tree|
|00004300| 2d 3e 63 6f 6c 6f 72 73 | 3b 0d 09 69 66 28 20 6f |->colors|;..if( o|
|00004310| 6c 64 49 6e 64 65 78 20 | 3d 3d 20 6e 65 77 49 6e |ldIndex |== newIn|
|00004320| 64 65 78 20 29 0d 09 09 | 72 65 74 75 72 6e 20 70 |dex )...|return p|
|00004330| 72 65 73 65 72 76 65 43 | 6f 6c 6f 72 3b 0d 0d 09 |reserveC|olor;...|
|00004340| 49 66 44 65 62 75 67 28 | 6e 65 77 49 6e 64 65 78 |IfDebug(|newIndex|
|00004350| 20 3e 20 6f 6c 64 49 6e | 64 65 78 2c 20 22 5c 70 | > oldIn|dex, "\p|
|00004360| 61 74 74 65 6d 70 74 69 | 6e 67 20 74 6f 20 72 65 |attempti|ng to re|
|00004370| 6d 6f 76 65 20 61 20 63 | 6f 6c 6f 72 20 74 68 61 |move a c|olor tha|
|00004380| 74 20 64 6f 65 73 6e 74 | 20 65 78 69 73 74 22 29 |t doesnt| exist")|
|00004390| 3b 0d 0d 2f 2a 09 69 66 | 20 74 68 65 20 63 6f 6c |;../*.if| the col|
|000043a0| 6f 72 20 77 65 20 61 72 | 65 20 6d 6f 76 69 6e 67 |or we ar|e moving|
|000043b0| 20 28 74 68 65 20 6c 61 | 73 74 20 63 6f 6c 6f 72 | (the la|st color|
|000043c0| 29 20 69 73 20 74 68 65 | 20 6f 6e 65 20 77 68 6f |) is the| one who|
|000043d0| 73 65 20 70 6f 69 6e 74 | 65 72 20 77 65 20 6e 65 |se point|er we ne|
|000043e0| 65 64 20 74 6f 20 70 72 | 65 73 65 72 76 65 2c 20 |ed to pr|eserve, |
|000043f0| 74 68 65 6e 20 72 65 73 | 65 74 20 69 74 73 20 70 |then res|et its p|
|00004400| 6f 69 6e 74 65 72 0d 09 | 74 6f 20 69 74 73 20 6e |ointer..|to its n|
|00004410| 65 77 20 6c 6f 63 61 74 | 69 6f 6e 2e 20 74 68 65 |ew locat|ion. the|
|00004420| 6e 20 63 6f 70 79 20 74 | 68 65 20 63 6f 6c 6f 72 |n copy t|he color|
|00004430| 20 73 74 72 75 63 74 75 | 72 65 20 66 72 6f 6d 20 | structu|re from |
|00004440| 74 68 65 20 6f 6c 64 20 | 70 6f 73 69 74 69 6f 6e |the old |position|
|00004450| 20 74 6f 20 74 68 65 20 | 6e 65 77 20 6f 6e 65 2e | to the |new one.|
|00004460| 20 2a 2f 0d 0d 09 69 66 | 28 20 26 74 72 65 65 2d | */...if|( &tree-|
|00004470| 3e 63 6f 6c 6f 72 42 61 | 73 65 5b 6f 6c 64 49 6e |>colorBa|se[oldIn|
|00004480| 64 65 78 5d 20 3d 3d 20 | 70 72 65 73 65 72 76 65 |dex] == |preserve|
|00004490| 43 6f 6c 6f 72 20 29 0d | 09 09 70 72 65 73 65 72 |Color ).|..preser|
|000044a0| 76 65 43 6f 6c 6f 72 20 | 3d 20 26 74 72 65 65 2d |veColor |= &tree-|
|000044b0| 3e 63 6f 6c 6f 72 42 61 | 73 65 5b 6e 65 77 49 6e |>colorBa|se[newIn|
|000044c0| 64 65 78 5d 3b 0d 09 74 | 72 65 65 2d 3e 63 6f 6c |dex];..t|ree->col|
|000044d0| 6f 72 42 61 73 65 5b 6e | 65 77 49 6e 64 65 78 5d |orBase[n|ewIndex]|
|000044e0| 20 3d 20 74 72 65 65 2d | 3e 63 6f 6c 6f 72 42 61 | = tree-|>colorBa|
|000044f0| 73 65 5b 6f 6c 64 49 6e | 64 65 78 5d 3b 0d 0d 2f |se[oldIn|dex];../|
|00004500| 2a 09 6c 6f 6f 6b 20 61 | 74 20 74 68 65 20 63 6f |*.look a|t the co|
|00004510| 6c 6f 72 20 77 65 20 61 | 72 65 20 6d 6f 76 69 6e |lor we a|re movin|
|00004520| 67 20 28 74 68 65 20 6c | 61 73 74 20 63 6f 6c 6f |g (the l|ast colo|
|00004530| 72 29 20 61 6e 64 20 67 | 65 74 20 69 74 73 20 6c |r) and g|et its l|
|00004540| 65 76 65 6c 2e 20 74 68 | 65 6e 20 73 63 61 6e 20 |evel. th|en scan |
|00004550| 74 68 72 6f 75 67 68 20 | 61 6c 6c 20 74 68 65 20 |through |all the |
|00004560| 63 6f 6c 6f 72 73 20 69 | 6e 20 74 68 65 20 6c 69 |colors i|n the li|
|00004570| 73 74 20 66 6f 72 0d 09 | 74 68 69 73 20 6c 65 76 |st for..|this lev|
|00004580| 65 6c 20 6c 6f 6f 6b 69 | 6e 67 20 66 6f 72 20 74 |el looki|ng for t|
|00004590| 68 65 20 6f 6e 65 20 74 | 68 61 74 20 77 65 20 72 |he one t|hat we r|
|000045a0| 65 6e 75 6d 62 65 72 65 | 64 2e 20 77 68 65 6e 20 |enumbere|d. when |
|000045b0| 77 65 20 66 69 6e 64 20 | 69 74 2c 20 74 68 65 6e |we find |it, then|
|000045c0| 20 77 65 20 72 65 6e 75 | 6d 62 65 72 20 69 74 2e | we renu|mber it.|
|000045d0| 20 2a 2f 0d 0d 09 7b 09 | 6f 63 74 72 65 65 43 6f | */...{.|octreeCo|
|000045e0| 6c 6f 72 20 2a 63 6f 6c | 6f 72 20 3d 20 26 74 72 |lor *col|or = &tr|
|000045f0| 65 65 2d 3e 63 6f 6c 6f | 72 42 61 73 65 5b 6f 6c |ee->colo|rBase[ol|
|00004600| 64 49 6e 64 65 78 5d 3b | 0d 09 09 69 66 28 20 74 |dIndex];|...if( t|
|00004610| 72 65 65 2d 3e 63 6f 6c | 6f 72 4c 69 73 74 5b 63 |ree->col|orList[c|
|00004620| 6f 6c 6f 72 2d 3e 6c 65 | 76 65 6c 5d 20 3d 3d 20 |olor->le|vel] == |
|00004630| 6f 6c 64 49 6e 64 65 78 | 20 29 20 7b 0d 09 09 09 |oldIndex| ) {....|
|00004640| 74 72 65 65 2d 3e 63 6f | 6c 6f 72 4c 69 73 74 5b |tree->co|lorList[|
|00004650| 63 6f 6c 6f 72 2d 3e 6c | 65 76 65 6c 5d 20 3d 20 |color->l|evel] = |
|00004660| 6e 65 77 49 6e 64 65 78 | 3b 0d 09 09 7d 20 65 6c |newIndex|;...} el|
|00004670| 73 65 20 7b 0d 09 09 09 | 73 68 6f 72 74 20 6c 65 |se {....|short le|
|00004680| 76 65 6c 49 6e 64 65 78 | 20 3d 20 74 72 65 65 2d |velIndex| = tree-|
|00004690| 3e 63 6f 6c 6f 72 4c 69 | 73 74 5b 63 6f 6c 6f 72 |>colorLi|st[color|
|000046a0| 2d 3e 6c 65 76 65 6c 5d | 3b 0d 09 09 09 77 68 69 |->level]|;....whi|
|000046b0| 6c 65 28 20 6c 65 76 65 | 6c 49 6e 64 65 78 20 21 |le( leve|lIndex !|
|000046c0| 3d 20 65 6d 70 74 79 4e | 6f 64 65 20 29 20 7b 0d |= emptyN|ode ) {.|
|000046d0| 09 09 09 09 63 6f 6c 6f | 72 20 3d 20 26 74 72 65 |....colo|r = &tre|
|000046e0| 65 2d 3e 63 6f 6c 6f 72 | 42 61 73 65 5b 6c 65 76 |e->color|Base[lev|
|000046f0| 65 6c 49 6e 64 65 78 5d | 3b 0d 09 09 09 09 49 66 |elIndex]|;.....If|
|00004700| 44 65 62 75 67 28 6c 65 | 76 65 6c 49 6e 64 65 78 |Debug(le|velIndex|
|00004710| 20 3e 20 74 72 65 65 2d | 3e 63 6f 6c 6f 72 73 2c | > tree-|>colors,|
|00004720| 20 22 5c 70 63 6f 6c 6f | 72 20 69 6e 20 63 6f 6c | "\pcolo|r in col|
|00004730| 6f 72 20 6c 69 73 74 20 | 64 6f 65 73 6e 74 20 65 |or list |doesnt e|
|00004740| 78 69 73 74 22 29 3b 0d | 09 09 09 09 69 66 28 20 |xist");.|....if( |
|00004750| 63 6f 6c 6f 72 2d 3e 6e | 65 78 74 20 3d 3d 20 6f |color->n|ext == o|
|00004760| 6c 64 49 6e 64 65 78 20 | 29 20 7b 0d 09 09 09 09 |ldIndex |) {.....|
|00004770| 09 63 6f 6c 6f 72 2d 3e | 6e 65 78 74 20 3d 20 6e |.color->|next = n|
|00004780| 65 77 49 6e 64 65 78 3b | 0d 09 09 09 09 09 62 72 |ewIndex;|......br|
|00004790| 65 61 6b 3b 0d 09 09 09 | 09 7d 0d 09 09 09 09 6c |eak;....|.}.....l|
|000047a0| 65 76 65 6c 49 6e 64 65 | 78 20 3d 20 63 6f 6c 6f |evelInde|x = colo|
|000047b0| 72 2d 3e 6e 65 78 74 3b | 0d 09 09 09 7d 0d 09 09 |r->next;|....}...|
|000047c0| 7d 0d 09 7d 0d 0d 2f 2a | 09 6c 6f 6f 6b 20 61 74 |}..}../*|.look at|
|000047d0| 20 74 68 65 20 63 6f 6c | 6f 72 20 77 65 20 61 72 | the col|or we ar|
|000047e0| 65 20 6d 6f 76 69 6e 67 | 20 28 74 68 65 20 6c 61 |e moving| (the la|
|000047f0| 73 74 20 63 6f 6c 6f 72 | 29 20 61 6e 64 20 67 65 |st color|) and ge|
|00004800| 74 20 69 74 73 20 70 61 | 72 65 6e 74 20 6e 6f 64 |t its pa|rent nod|
|00004810| 65 2e 20 74 68 65 6e 20 | 73 63 61 6e 20 74 68 72 |e. then |scan thr|
|00004820| 6f 75 67 68 20 61 6c 6c | 20 74 68 65 20 63 68 69 |ough all| the chi|
|00004830| 6c 64 72 65 6e 20 6f 66 | 20 74 68 69 73 0d 09 70 |ldren of| this..p|
|00004840| 61 72 65 6e 74 20 74 6f | 20 66 69 6e 64 20 74 68 |arent to| find th|
|00004850| 65 20 65 6e 74 72 79 20 | 74 68 61 74 20 70 6f 69 |e entry |that poi|
|00004860| 6e 74 73 20 74 6f 20 74 | 68 65 20 6f 6c 64 20 6c |nts to t|he old l|
|00004870| 6f 63 61 74 69 6f 6e 20 | 61 6e 64 20 75 70 64 61 |ocation |and upda|
|00004880| 74 65 20 69 74 20 74 6f | 20 63 6f 6e 74 61 69 6e |te it to| contain|
|00004890| 20 74 68 65 20 69 6e 64 | 65 78 20 6f 66 20 74 68 | the ind|ex of th|
|000048a0| 65 20 6e 65 77 20 6c 6f | 63 61 74 69 6f 6e 2e 20 |e new lo|cation. |
|000048b0| 2a 2f 0d 0d 09 7b 09 6f | 63 74 72 65 65 43 6f 6c |*/...{.o|ctreeCol|
|000048c0| 6f 72 20 2a 63 6f 6c 6f | 72 20 3d 20 26 74 72 65 |or *colo|r = &tre|
|000048d0| 65 2d 3e 63 6f 6c 6f 72 | 42 61 73 65 5b 6e 65 77 |e->color|Base[new|
|000048e0| 49 6e 64 65 78 5d 3b 0d | 0d 09 09 69 66 28 20 63 |Index];.|...if( c|
|000048f0| 6f 6c 6f 72 2d 3e 70 61 | 72 65 6e 74 20 21 3d 20 |olor->pa|rent != |
|00004900| 65 6d 70 74 79 4e 6f 64 | 65 20 29 20 7b 0d 09 09 |emptyNod|e ) {...|
|00004910| 09 6f 63 74 72 65 65 4e | 6f 64 65 20 2a 6e 6f 64 |.octreeN|ode *nod|
|00004920| 65 20 3d 20 26 74 72 65 | 65 2d 3e 6e 6f 64 65 42 |e = &tre|e->nodeB|
|00004930| 61 73 65 5b 63 6f 6c 6f | 72 2d 3e 70 61 72 65 6e |ase[colo|r->paren|
|00004940| 74 5d 3b 0d 09 09 09 73 | 68 6f 72 74 20 63 6f 75 |t];....s|hort cou|
|00004950| 6e 74 65 72 20 3d 20 38 | 3b 0d 0d 09 09 09 49 66 |nter = 8|;.....If|
|00004960| 44 65 62 75 67 28 63 6f | 6c 6f 72 2d 3e 70 61 72 |Debug(co|lor->par|
|00004970| 65 6e 74 20 3e 3d 20 74 | 72 65 65 2d 3e 6e 6f 64 |ent >= t|ree->nod|
|00004980| 65 73 2c 20 22 5c 70 63 | 6f 6c 6f 72 20 68 61 73 |es, "\pc|olor has|
|00004990| 20 61 6e 20 69 6e 76 61 | 6c 69 64 20 70 61 72 65 | an inva|lid pare|
|000049a0| 6e 74 22 29 3b 0d 09 09 | 09 49 66 44 65 62 75 67 |nt");...|.IfDebug|
|000049b0| 28 6e 6f 64 65 2d 3e 63 | 68 69 6c 64 72 65 6e 20 |(node->c|hildren |
|000049c0| 3d 3d 20 6f 62 73 6f 6c | 65 74 65 4e 6f 64 65 2c |== obsol|eteNode,|
|000049d0| 20 22 5c 70 63 6f 6c 6f | 72 73 20 70 61 72 65 6e | "\pcolo|rs paren|
|000049e0| 74 20 69 73 20 6f 62 73 | 6f 6c 65 74 65 22 29 3b |t is obs|olete");|
|000049f0| 0d 0d 09 09 09 6f 6c 64 | 49 6e 64 65 78 20 3d 20 |.....old|Index = |
|00004a00| 7e 6f 6c 64 49 6e 64 65 | 78 3b 0d 09 09 09 77 68 |~oldInde|x;....wh|
|00004a10| 69 6c 65 28 20 2d 2d 63 | 6f 75 6e 74 65 72 20 3e |ile( --c|ounter >|
|00004a20| 3d 20 30 20 29 20 7b 0d | 09 09 09 09 69 66 28 20 |= 0 ) {.|....if( |
|00004a30| 6e 6f 64 65 2d 3e 6c 65 | 61 66 5b 63 6f 75 6e 74 |node->le|af[count|
|00004a40| 65 72 5d 20 3d 3d 20 6f | 6c 64 49 6e 64 65 78 20 |er] == o|ldIndex |
|00004a50| 29 20 7b 0d 09 09 09 09 | 09 6e 6f 64 65 2d 3e 6c |) {.....|.node->l|
|00004a60| 65 61 66 5b 63 6f 75 6e | 74 65 72 5d 20 3d 20 7e |eaf[coun|ter] = ~|
|00004a70| 6e 65 77 49 6e 64 65 78 | 3b 0d 09 09 09 09 09 56 |newIndex|;......V|
|00004a80| 61 6c 69 64 61 74 65 54 | 72 65 65 28 74 72 65 65 |alidateT|ree(tree|
|00004a90| 29 3b 0d 09 09 09 09 09 | 72 65 74 75 72 6e 20 70 |);......|return p|
|00004aa0| 72 65 73 65 72 76 65 43 | 6f 6c 6f 72 3b 0d 09 09 |reserveC|olor;...|
|00004ab0| 09 09 7d 0d 09 09 09 7d | 0d 09 09 09 49 66 44 65 |..}....}|....IfDe|
|00004ac0| 62 75 67 28 31 2c 20 22 | 5c 70 63 61 6e 74 20 66 |bug(1, "|\pcant f|
|00004ad0| 69 6e 64 20 6c 61 73 74 | 20 63 6f 6c 6f 72 20 69 |ind last| color i|
|00004ae0| 6e 20 69 74 73 20 70 61 | 72 65 6e 74 20 6e 6f 64 |n its pa|rent nod|
|00004af0| 65 22 29 3b 0d 09 09 7d | 0d 09 7d 0d 0d 09 72 65 |e");...}|..}...re|
|00004b00| 74 75 72 6e 20 70 72 65 | 73 65 72 76 65 43 6f 6c |turn pre|serveCol|
|00004b10| 6f 72 3b 0d 7d 0d 0d 0d | 73 74 61 74 69 63 20 6f |or;.}...|static o|
|00004b20| 63 74 72 65 65 43 6f 6c | 6f 72 20 2a 52 65 64 75 |ctreeCol|or *Redu|
|00004b30| 63 65 4e 6f 64 65 28 6f | 63 74 72 65 65 20 2a 74 |ceNode(o|ctree *t|
|00004b40| 72 65 65 2c 20 6f 63 74 | 72 65 65 4e 6f 64 65 20 |ree, oct|reeNode |
|00004b50| 2a 62 61 73 65 2c 20 6f | 63 74 72 65 65 43 6f 6c |*base, o|ctreeCol|
|00004b60| 6f 72 20 2a 72 65 73 75 | 6c 74 43 6f 6c 6f 72 29 |or *resu|ltColor)|
|00004b70| 0d 7b 0d 09 73 68 6f 72 | 74 20 69 6e 64 65 78 3b |.{..shor|t index;|
|00004b80| 0d 09 73 68 6f 72 74 20 | 63 6f 75 6e 74 65 72 20 |..short |counter |
|00004b90| 3d 20 38 3b 0d 0d 09 56 | 61 6c 69 64 61 74 65 54 |= 8;...V|alidateT|
|00004ba0| 72 65 65 28 74 72 65 65 | 29 3b 0d 09 77 68 69 6c |ree(tree|);..whil|
|00004bb0| 65 28 20 2d 2d 63 6f 75 | 6e 74 65 72 20 3e 3d 20 |e( --cou|nter >= |
|00004bc0| 30 20 29 20 7b 0d 09 09 | 69 6e 64 65 78 20 3d 20 |0 ) {...|index = |
|00004bd0| 62 61 73 65 2d 3e 6c 65 | 61 66 5b 63 6f 75 6e 74 |base->le|af[count|
|00004be0| 65 72 5d 3b 0d 09 09 69 | 66 28 20 69 6e 64 65 78 |er];...i|f( index|
|00004bf0| 20 3d 3d 20 65 6d 70 74 | 79 4e 6f 64 65 20 29 0d | == empt|yNode ).|
|00004c00| 09 09 09 63 6f 6e 74 69 | 6e 75 65 3b 0d 09 09 69 |...conti|nue;...i|
|00004c10| 66 28 20 69 6e 64 65 78 | 20 3e 3d 20 30 20 29 20 |f( index| >= 0 ) |
|00004c20| 7b 0d 09 09 09 49 66 44 | 65 62 75 67 28 69 6e 64 |{....IfD|ebug(ind|
|00004c30| 65 78 20 3e 3d 20 74 72 | 65 65 2d 3e 6e 6f 64 65 |ex >= tr|ee->node|
|00004c40| 73 2c 20 22 5c 70 61 74 | 74 65 6d 70 74 69 6e 67 |s, "\pat|tempting|
|00004c50| 20 74 6f 20 72 65 64 75 | 63 65 20 61 20 6e 6f 64 | to redu|ce a nod|
|00004c60| 65 20 74 68 61 74 20 64 | 6f 65 73 6e 74 20 65 78 |e that d|oesnt ex|
|00004c70| 69 73 74 22 29 3b 0d 09 | 09 09 72 65 73 75 6c 74 |ist");..|..result|
|00004c80| 43 6f 6c 6f 72 20 3d 20 | 52 65 64 75 63 65 4e 6f |Color = |ReduceNo|
|00004c90| 64 65 28 74 72 65 65 2c | 20 26 74 72 65 65 2d 3e |de(tree,| &tree->|
|00004ca0| 6e 6f 64 65 42 61 73 65 | 5b 69 6e 64 65 78 5d 2c |nodeBase|[index],|
|00004cb0| 20 72 65 73 75 6c 74 43 | 6f 6c 6f 72 29 3b 0d 09 | resultC|olor);..|
|00004cc0| 09 7d 20 65 6c 73 65 20 | 7b 0d 09 09 09 6f 63 74 |.} else |{....oct|
|00004cd0| 72 65 65 43 6f 6c 6f 72 | 20 2a 6e 65 77 43 6f 6c |reeColor| *newCol|
|00004ce0| 6f 72 20 3d 20 26 74 72 | 65 65 2d 3e 63 6f 6c 6f |or = &tr|ee->colo|
|00004cf0| 72 42 61 73 65 5b 7e 69 | 6e 64 65 78 5d 3b 0d 09 |rBase[~i|ndex];..|
|00004d00| 09 09 49 66 44 65 62 75 | 67 28 7e 69 6e 64 65 78 |..IfDebu|g(~index|
|00004d10| 20 3e 3d 20 74 72 65 65 | 2d 3e 63 6f 6c 6f 72 73 | >= tree|->colors|
|00004d20| 2c 20 22 5c 70 61 74 74 | 65 6d 70 74 69 6e 67 20 |, "\patt|empting |
|00004d30| 74 6f 20 72 65 6d 6f 76 | 65 20 61 20 63 6f 6c 6f |to remov|e a colo|
|00004d40| 72 20 74 68 61 74 20 64 | 6f 65 73 6e 74 20 65 78 |r that d|oesnt ex|
|00004d50| 69 73 74 22 29 3b 0d 09 | 09 09 69 66 28 20 72 65 |ist");..|..if( re|
|00004d60| 73 75 6c 74 43 6f 6c 6f | 72 20 21 3d 20 6e 65 77 |sultColo|r != new|
|00004d70| 43 6f 6c 6f 72 20 29 20 | 7b 0d 09 09 09 09 62 61 |Color ) |{.....ba|
|00004d80| 73 65 2d 3e 6c 65 61 66 | 5b 63 6f 75 6e 74 65 72 |se->leaf|[counter|
|00004d90| 5d 20 3d 20 65 6d 70 74 | 79 4e 6f 64 65 3b 0d 09 |] = empt|yNode;..|
|00004da0| 09 09 09 6e 65 77 43 6f | 6c 6f 72 2d 3e 70 61 72 |...newCo|lor->par|
|00004db0| 65 6e 74 20 3d 20 65 6d | 70 74 79 4e 6f 64 65 3b |ent = em|ptyNode;|
|00004dc0| 0d 09 09 09 09 72 65 73 | 75 6c 74 43 6f 6c 6f 72 |.....res|ultColor|
|00004dd0| 2d 3e 63 6f 75 6e 74 20 | 2b 3d 20 6e 65 77 43 6f |->count |+= newCo|
|00004de0| 6c 6f 72 2d 3e 63 6f 75 | 6e 74 3b 0d 09 09 09 09 |lor->cou|nt;.....|
|00004df0| 72 65 73 75 6c 74 43 6f | 6c 6f 72 2d 3e 74 6f 74 |resultCo|lor->tot|
|00004e00| 61 6c 52 65 64 20 2b 3d | 20 6e 65 77 43 6f 6c 6f |alRed +=| newColo|
|00004e10| 72 2d 3e 74 6f 74 61 6c | 52 65 64 3b 0d 09 09 09 |r->total|Red;....|
|00004e20| 09 72 65 73 75 6c 74 43 | 6f 6c 6f 72 2d 3e 74 6f |.resultC|olor->to|
|00004e30| 74 61 6c 47 72 65 65 6e | 20 2b 3d 20 6e 65 77 43 |talGreen| += newC|
|00004e40| 6f 6c 6f 72 2d 3e 74 6f | 74 61 6c 47 72 65 65 6e |olor->to|talGreen|
|00004e50| 3b 0d 09 09 09 09 72 65 | 73 75 6c 74 43 6f 6c 6f |;.....re|sultColo|
|00004e60| 72 2d 3e 74 6f 74 61 6c | 42 6c 75 65 20 2b 3d 20 |r->total|Blue += |
|00004e70| 6e 65 77 43 6f 6c 6f 72 | 2d 3e 74 6f 74 61 6c 42 |newColor|->totalB|
|00004e80| 6c 75 65 3b 0d 09 09 09 | 09 72 65 73 75 6c 74 43 |lue;....|.resultC|
|00004e90| 6f 6c 6f 72 20 3d 20 52 | 65 6d 6f 76 65 43 6f 6c |olor = R|emoveCol|
|00004ea0| 6f 72 28 74 72 65 65 2c | 20 7e 69 6e 64 65 78 2c |or(tree,| ~index,|
|00004eb0| 20 72 65 73 75 6c 74 43 | 6f 6c 6f 72 29 3b 0d 09 | resultC|olor);..|
|00004ec0| 09 09 7d 0d 09 09 7d 0d | 09 7d 0d 09 62 61 73 65 |..}...}.|.}..base|
|00004ed0| 2d 3e 63 68 69 6c 64 72 | 65 6e 20 3d 20 6f 62 73 |->childr|en = obs|
|00004ee0| 6f 6c 65 74 65 4e 6f 64 | 65 3b 0d 09 56 61 6c 69 |oleteNod|e;..Vali|
|00004ef0| 64 61 74 65 54 72 65 65 | 28 74 72 65 65 29 3b 0d |dateTree|(tree);.|
|00004f00| 09 72 65 74 75 72 6e 20 | 72 65 73 75 6c 74 43 6f |.return |resultCo|
|00004f10| 6c 6f 72 3b 0d 7d 0d 0d | 0d 73 74 61 74 69 63 20 |lor;.}..|.static |
|00004f20| 76 6f 69 64 20 52 65 6d | 6f 76 65 4f 62 73 6f 6c |void Rem|oveObsol|
|00004f30| 65 74 65 4e 6f 64 65 73 | 28 6f 63 74 72 65 65 20 |eteNodes|(octree |
|00004f40| 2a 74 72 65 65 29 0d 7b | 0d 09 6f 63 74 72 65 65 |*tree).{|..octree|
|00004f50| 4e 6f 64 65 20 2a 6f 75 | 74 65 72 4e 6f 64 65 20 |Node *ou|terNode |
|00004f60| 3d 20 26 74 72 65 65 2d | 3e 6e 6f 64 65 42 61 73 |= &tree-|>nodeBas|
|00004f70| 65 5b 30 5d 3b 0d 09 73 | 68 6f 72 74 20 6f 75 74 |e[0];..s|hort out|
|00004f80| 65 72 4e 6f 64 65 73 20 | 3d 20 74 72 65 65 2d 3e |erNodes |= tree->|
|00004f90| 6e 6f 64 65 73 3b 0d 0d | 09 56 61 6c 69 64 61 74 |nodes;..|.Validat|
|00004fa0| 65 54 72 65 65 28 74 72 | 65 65 29 3b 0d 0d 09 77 |eTree(tr|ee);...w|
|00004fb0| 68 69 6c 65 28 20 2d 2d | 6f 75 74 65 72 4e 6f 64 |hile( --|outerNod|
|00004fc0| 65 73 20 3e 3d 20 30 20 | 29 20 7b 0d 09 09 69 66 |es >= 0 |) {...if|
|00004fd0| 28 20 6f 75 74 65 72 4e | 6f 64 65 2d 3e 63 68 69 |( outerN|ode->chi|
|00004fe0| 6c 64 72 65 6e 20 3d 3d | 20 6f 62 73 6f 6c 65 74 |ldren ==| obsolet|
|00004ff0| 65 4e 6f 64 65 20 29 20 | 7b 0d 09 09 09 6f 63 74 |eNode ) |{....oct|
|00005000| 72 65 65 4e 6f 64 65 20 | 2a 6e 6f 64 65 20 3d 20 |reeNode |*node = |
|00005010| 6f 75 74 65 72 4e 6f 64 | 65 3b 0d 09 09 09 6f 63 |outerNod|e;....oc|
|00005020| 74 72 65 65 4e 6f 64 65 | 20 2a 70 61 72 65 6e 74 |treeNode| *parent|
|00005030| 3b 0d 09 09 09 73 68 6f | 72 74 20 6e 65 77 49 6e |;....sho|rt newIn|
|00005040| 64 65 78 20 3d 20 6f 75 | 74 65 72 4e 6f 64 65 20 |dex = ou|terNode |
|00005050| 2d 20 26 74 72 65 65 2d | 3e 6e 6f 64 65 42 61 73 |- &tree-|>nodeBas|
|00005060| 65 5b 30 5d 3b 0d 09 09 | 09 73 68 6f 72 74 20 6f |e[0];...|.short o|
|00005070| 6c 64 49 6e 64 65 78 3b | 0d 09 09 09 73 68 6f 72 |ldIndex;|....shor|
|00005080| 74 20 63 6f 75 6e 74 65 | 72 3b 0d 0d 09 09 09 77 |t counte|r;.....w|
|00005090| 68 69 6c 65 28 20 6e 6f | 64 65 2d 3e 63 68 69 6c |hile( no|de->chil|
|000050a0| 64 72 65 6e 20 3d 3d 20 | 6f 62 73 6f 6c 65 74 65 |dren == |obsolete|
|000050b0| 4e 6f 64 65 20 29 20 7b | 0d 09 09 09 09 6f 6c 64 |Node ) {|.....old|
|000050c0| 49 6e 64 65 78 20 3d 20 | 28 2d 2d 6f 75 74 65 72 |Index = |(--outer|
|000050d0| 4e 6f 64 65 73 2c 20 2d | 2d 74 72 65 65 2d 3e 6e |Nodes, -|-tree->n|
|000050e0| 6f 64 65 73 29 3b 0d 09 | 09 09 09 69 66 28 20 6f |odes);..|...if( o|
|000050f0| 75 74 65 72 4e 6f 64 65 | 73 20 3c 20 30 20 29 20 |uterNode|s < 0 ) |
|00005100| 7b 0d 09 09 09 09 09 56 | 61 6c 69 64 61 74 65 54 |{......V|alidateT|
|00005110| 72 65 65 28 74 72 65 65 | 29 3b 0d 09 09 09 09 09 |ree(tree|);......|
|00005120| 72 65 74 75 72 6e 3b 0d | 09 09 09 09 7d 0d 09 09 |return;.|....}...|
|00005130| 09 09 6e 6f 64 65 20 3d | 20 26 74 72 65 65 2d 3e |..node =| &tree->|
|00005140| 6e 6f 64 65 42 61 73 65 | 5b 6f 6c 64 49 6e 64 65 |nodeBase|[oldInde|
|00005150| 78 5d 3b 0d 09 09 09 7d | 0d 0d 09 09 09 70 61 72 |x];....}|.....par|
|00005160| 65 6e 74 20 3d 20 26 74 | 72 65 65 2d 3e 6e 6f 64 |ent = &t|ree->nod|
|00005170| 65 42 61 73 65 5b 6e 6f | 64 65 2d 3e 70 61 72 65 |eBase[no|de->pare|
|00005180| 6e 74 5d 3b 0d 0d 09 09 | 09 63 6f 75 6e 74 65 72 |nt];....|.counter|
|00005190| 20 3d 20 38 3b 0d 09 09 | 09 77 68 69 6c 65 28 20 | = 8;...|.while( |
|000051a0| 2d 2d 63 6f 75 6e 74 65 | 72 20 3e 3d 20 30 20 29 |--counte|r >= 0 )|
|000051b0| 20 7b 0d 09 09 09 09 69 | 66 28 20 70 61 72 65 6e | {.....i|f( paren|
|000051c0| 74 2d 3e 6c 65 61 66 5b | 63 6f 75 6e 74 65 72 5d |t->leaf[|counter]|
|000051d0| 20 3d 3d 20 6f 6c 64 49 | 6e 64 65 78 20 29 20 7b | == oldI|ndex ) {|
|000051e0| 0d 09 09 09 09 09 70 61 | 72 65 6e 74 2d 3e 6c 65 |......pa|rent->le|
|000051f0| 61 66 5b 63 6f 75 6e 74 | 65 72 5d 20 3d 20 6e 65 |af[count|er] = ne|
|00005200| 77 49 6e 64 65 78 3b 0d | 09 09 09 09 09 67 6f 74 |wIndex;.|.....got|
|00005210| 6f 20 66 69 78 43 68 69 | 6c 64 72 65 6e 3b 0d 09 |o fixChi|ldren;..|
|00005220| 09 09 09 7d 0d 09 09 09 | 7d 0d 09 09 09 49 66 44 |...}....|}....IfD|
|00005230| 65 62 75 67 28 31 2c 20 | 22 5c 70 63 61 6e 74 20 |ebug(1, |"\pcant |
|00005240| 66 69 6e 64 20 74 68 65 | 20 6e 6f 64 65 20 77 65 |find the| node we|
|00005250| 20 61 72 65 20 6d 6f 76 | 69 6e 67 20 69 6e 20 69 | are mov|ing in i|
|00005260| 74 73 20 70 61 72 65 6e | 74 73 20 6c 69 73 74 20 |ts paren|ts list |
|00005270| 6f 66 20 63 68 69 6c 64 | 72 65 6e 22 29 3b 0d 66 |of child|ren");.f|
|00005280| 69 78 43 68 69 6c 64 72 | 65 6e 3a 0d 09 09 09 63 |ixChildr|en:....c|
|00005290| 6f 75 6e 74 65 72 20 3d | 20 38 3b 0d 09 09 09 77 |ounter =| 8;....w|
|000052a0| 68 69 6c 65 28 20 2d 2d | 63 6f 75 6e 74 65 72 20 |hile( --|counter |
|000052b0| 3e 3d 20 30 20 29 20 7b | 0d 09 09 09 09 73 68 6f |>= 0 ) {|.....sho|
|000052c0| 72 74 20 69 6e 64 65 78 | 20 3d 20 6e 6f 64 65 2d |rt index| = node-|
|000052d0| 3e 6c 65 61 66 5b 63 6f | 75 6e 74 65 72 5d 3b 0d |>leaf[co|unter];.|
|000052e0| 09 09 09 09 69 66 28 20 | 69 6e 64 65 78 20 3d 3d |....if( |index ==|
|000052f0| 20 65 6d 70 74 79 4e 6f | 64 65 20 29 0d 09 09 09 | emptyNo|de )....|
|00005300| 09 09 63 6f 6e 74 69 6e | 75 65 3b 0d 09 09 09 09 |..contin|ue;.....|
|00005310| 69 66 28 20 69 6e 64 65 | 78 20 3e 3d 20 30 20 29 |if( inde|x >= 0 )|
|00005320| 20 7b 0d 09 09 09 09 09 | 6f 63 74 72 65 65 4e 6f | {......|octreeNo|
|00005330| 64 65 20 2a 63 68 69 6c | 64 20 3d 20 26 74 72 65 |de *chil|d = &tre|
|00005340| 65 2d 3e 6e 6f 64 65 42 | 61 73 65 5b 69 6e 64 65 |e->nodeB|ase[inde|
|00005350| 78 5d 3b 0d 09 09 09 09 | 09 49 66 44 65 62 75 67 |x];.....|.IfDebug|
|00005360| 28 63 68 69 6c 64 2d 3e | 70 61 72 65 6e 74 20 21 |(child->|parent !|
|00005370| 3d 20 6f 6c 64 49 6e 64 | 65 78 2c 20 22 5c 70 63 |= oldInd|ex, "\pc|
|00005380| 68 69 6c 64 20 64 6f 65 | 73 20 6e 6f 74 20 70 6f |hild doe|s not po|
|00005390| 69 6e 74 20 62 61 63 6b | 20 74 6f 20 63 6f 72 72 |int back| to corr|
|000053a0| 65 63 74 20 70 61 72 65 | 6e 74 22 29 3b 0d 09 09 |ect pare|nt");...|
|000053b0| 09 09 09 63 68 69 6c 64 | 2d 3e 70 61 72 65 6e 74 |...child|->parent|
|000053c0| 20 3d 20 6e 65 77 49 6e | 64 65 78 3b 0d 09 09 09 | = newIn|dex;....|
|000053d0| 09 7d 20 65 6c 73 65 20 | 7b 0d 09 09 09 09 09 6f |.} else |{......o|
|000053e0| 63 74 72 65 65 43 6f 6c | 6f 72 20 2a 63 68 69 6c |ctreeCol|or *chil|
|000053f0| 64 20 3d 20 26 74 72 65 | 65 2d 3e 63 6f 6c 6f 72 |d = &tre|e->color|
|00005400| 42 61 73 65 5b 7e 69 6e | 64 65 78 5d 3b 0d 09 09 |Base[~in|dex];...|
|00005410| 09 09 09 49 66 44 65 62 | 75 67 28 63 68 69 6c 64 |...IfDeb|ug(child|
|00005420| 2d 3e 70 61 72 65 6e 74 | 20 21 3d 20 6f 6c 64 49 |->parent| != oldI|
|00005430| 6e 64 65 78 2c 20 22 5c | 70 63 68 69 6c 64 20 64 |ndex, "\|pchild d|
|00005440| 6f 65 73 20 6e 6f 74 20 | 70 6f 69 6e 74 20 62 61 |oes not |point ba|
|00005450| 63 6b 20 74 6f 20 63 6f | 72 72 65 63 74 20 70 61 |ck to co|rrect pa|
|00005460| 72 65 6e 74 22 29 3b 0d | 09 09 09 09 09 63 68 69 |rent");.|.....chi|
|00005470| 6c 64 2d 3e 70 61 72 65 | 6e 74 20 3d 20 6e 65 77 |ld->pare|nt = new|
|00005480| 49 6e 64 65 78 3b 0d 09 | 09 09 09 7d 0d 09 09 09 |Index;..|...}....|
|00005490| 7d 0d 0d 09 09 09 74 72 | 65 65 2d 3e 6e 6f 64 65 |}.....tr|ee->node|
|000054a0| 42 61 73 65 5b 6e 65 77 | 49 6e 64 65 78 5d 20 3d |Base[new|Index] =|
|000054b0| 20 74 72 65 65 2d 3e 6e | 6f 64 65 42 61 73 65 5b | tree->n|odeBase[|
|000054c0| 6f 6c 64 49 6e 64 65 78 | 5d 3b 0d 09 09 7d 0d 6e |oldIndex|];...}.n|
|000054d0| 65 78 74 3a 09 2b 2b 6f | 75 74 65 72 4e 6f 64 65 |ext:.++o|uterNode|
|000054e0| 3b 0d 09 7d 0d 09 56 61 | 6c 69 64 61 74 65 54 72 |;..}..Va|lidateTr|
|000054f0| 65 65 28 74 72 65 65 29 | 3b 0d 7d 0d 0d 0d 73 74 |ee(tree)|;.}...st|
|00005500| 61 74 69 63 20 76 6f 69 | 64 20 52 65 64 75 63 65 |atic voi|d Reduce|
|00005510| 4f 63 74 72 65 65 28 6f | 63 74 72 65 65 20 2a 74 |Octree(o|ctree *t|
|00005520| 72 65 65 29 0d 7b 0d 09 | 6f 63 74 72 65 65 43 6f |ree).{..|octreeCo|
|00005530| 6c 6f 72 20 2a 63 6f 6c | 6f 72 3b 0d 09 6f 63 74 |lor *col|or;..oct|
|00005540| 72 65 65 4e 6f 64 65 20 | 2a 6e 6f 64 65 3b 0d 09 |reeNode |*node;..|
|00005550| 73 68 6f 72 74 20 6c 65 | 76 65 6c 3b 0d 09 73 68 |short le|vel;..sh|
|00005560| 6f 72 74 20 69 6e 64 65 | 78 3b 0d 0d 09 69 66 28 |ort inde|x;...if(|
|00005570| 20 74 72 65 65 2d 3e 63 | 6f 6c 6f 72 73 20 3c 20 | tree->c|olors < |
|00005580| 74 72 65 65 2d 3e 6d 61 | 78 69 6d 75 6d 43 6f 6c |tree->ma|ximumCol|
|00005590| 6f 72 73 20 29 0d 09 09 | 72 65 74 75 72 6e 3b 0d |ors )...|return;.|
|000055a0| 0d 09 56 61 6c 69 64 61 | 74 65 54 72 65 65 28 74 |..Valida|teTree(t|
|000055b0| 72 65 65 29 3b 0d 09 6c | 65 76 65 6c 20 3d 20 6d |ree);..l|evel = m|
|000055c0| 61 78 69 6d 75 6d 4c 65 | 76 65 6c 3b 0d 09 77 68 |aximumLe|vel;..wh|
|000055d0| 69 6c 65 28 20 6c 65 76 | 65 6c 20 3e 20 30 20 29 |ile( lev|el > 0 )|
|000055e0| 20 7b 0d 09 09 73 68 6f | 72 74 20 69 6e 6e 65 72 | {...sho|rt inner|
|000055f0| 4c 65 76 65 6c 20 3d 20 | 6c 65 76 65 6c 3b 0d 0d |Level = |level;..|
|00005600| 09 09 77 68 69 6c 65 28 | 20 69 6e 6e 65 72 4c 65 |..while(| innerLe|
|00005610| 76 65 6c 20 3c 3d 20 6d | 61 78 69 6d 75 6d 4c 65 |vel <= m|aximumLe|
|00005620| 76 65 6c 20 29 20 7b 0d | 09 09 09 69 6e 64 65 78 |vel ) {.|...index|
|00005630| 20 3d 20 74 72 65 65 2d | 3e 63 6f 6c 6f 72 4c 69 | = tree-|>colorLi|
|00005640| 73 74 5b 69 6e 6e 65 72 | 4c 65 76 65 6c 5d 3b 0d |st[inner|Level];.|
|00005650| 09 09 09 77 68 69 6c 65 | 28 20 69 6e 64 65 78 20 |...while|( index |
|00005660| 21 3d 20 65 6d 70 74 79 | 4e 6f 64 65 20 29 20 7b |!= empty|Node ) {|
|00005670| 0d 09 09 09 09 73 68 6f | 72 74 20 70 61 72 65 6e |.....sho|rt paren|
|00005680| 74 49 6e 64 65 78 3b 0d | 0d 09 09 09 09 49 66 44 |tIndex;.|.....IfD|
|00005690| 65 62 75 67 28 69 6e 64 | 65 78 20 3e 3d 20 74 72 |ebug(ind|ex >= tr|
|000056a0| 65 65 2d 3e 63 6f 6c 6f | 72 73 2c 20 22 5c 70 69 |ee->colo|rs, "\pi|
|000056b0| 6e 76 61 6c 69 64 20 63 | 6f 6c 6f 72 20 69 6e 20 |nvalid c|olor in |
|000056c0| 74 68 65 20 63 6f 6c 6f | 72 20 6c 69 73 74 22 29 |the colo|r list")|
|000056d0| 3b 0d 09 09 09 09 63 6f | 6c 6f 72 20 3d 20 26 74 |;.....co|lor = &t|
|000056e0| 72 65 65 2d 3e 63 6f 6c | 6f 72 42 61 73 65 5b 69 |ree->col|orBase[i|
|000056f0| 6e 64 65 78 5d 3b 0d 09 | 09 09 09 70 61 72 65 6e |ndex];..|...paren|
|00005700| 74 49 6e 64 65 78 20 3d | 20 63 6f 6c 6f 72 2d 3e |tIndex =| color->|
|00005710| 70 61 72 65 6e 74 3b 0d | 09 09 09 09 49 66 44 65 |parent;.|....IfDe|
|00005720| 62 75 67 28 70 61 72 65 | 6e 74 49 6e 64 65 78 20 |bug(pare|ntIndex |
|00005730| 3e 3d 20 74 72 65 65 2d | 3e 6e 6f 64 65 73 2c 20 |>= tree-|>nodes, |
|00005740| 22 5c 70 63 6f 6c 6f 72 | 20 68 61 73 20 69 6e 76 |"\pcolor| has inv|
|00005750| 61 6c 69 64 20 70 61 72 | 65 6e 74 22 29 3b 0d 09 |alid par|ent");..|
|00005760| 09 09 09 6e 6f 64 65 20 | 3d 20 26 74 72 65 65 2d |...node |= &tree-|
|00005770| 3e 6e 6f 64 65 42 61 73 | 65 5b 70 61 72 65 6e 74 |>nodeBas|e[parent|
|00005780| 49 6e 64 65 78 5d 3b 0d | 0d 09 09 09 09 7b 09 73 |Index];.|.....{.s|
|00005790| 68 6f 72 74 20 74 65 6d | 70 4c 65 76 65 6c 20 3d |hort tem|pLevel =|
|000057a0| 20 69 6e 6e 65 72 4c 65 | 76 65 6c 3b 0d 09 09 09 | innerLe|vel;....|
|000057b0| 09 09 77 68 69 6c 65 28 | 20 74 65 6d 70 4c 65 76 |..while(| tempLev|
|000057c0| 65 6c 20 3e 20 6c 65 76 | 65 6c 20 29 20 7b 0d 09 |el > lev|el ) {..|
|000057d0| 09 09 09 09 09 70 61 72 | 65 6e 74 49 6e 64 65 78 |.....par|entIndex|
|000057e0| 20 3d 20 6e 6f 64 65 2d | 3e 70 61 72 65 6e 74 3b | = node-|>parent;|
|000057f0| 0d 09 09 09 09 09 09 49 | 66 44 65 62 75 67 28 70 |.......I|fDebug(p|
|00005800| 61 72 65 6e 74 49 6e 64 | 65 78 20 3e 3d 20 74 72 |arentInd|ex >= tr|
|00005810| 65 65 2d 3e 6e 6f 64 65 | 73 2c 20 22 5c 70 6e 6f |ee->node|s, "\pno|
|00005820| 64 65 20 68 61 73 20 69 | 6e 76 61 6c 69 64 20 70 |de has i|nvalid p|
|00005830| 61 72 65 6e 74 22 29 3b | 0d 09 09 09 09 09 09 6e |arent");|.......n|
|00005840| 6f 64 65 20 3d 20 26 74 | 72 65 65 2d 3e 6e 6f 64 |ode = &t|ree->nod|
|00005850| 65 42 61 73 65 5b 70 61 | 72 65 6e 74 49 6e 64 65 |eBase[pa|rentInde|
|00005860| 78 5d 3b 0d 09 09 09 09 | 09 09 2d 2d 74 65 6d 70 |x];.....|..--temp|
|00005870| 4c 65 76 65 6c 3b 0d 09 | 09 09 09 09 7d 0d 09 09 |Level;..|....}...|
|00005880| 09 09 7d 0d 0d 09 09 09 | 09 69 66 28 20 6e 6f 64 |..}.....|.if( nod|
|00005890| 65 2d 3e 63 68 69 6c 64 | 72 65 6e 20 3e 20 31 20 |e->child|ren > 1 |
|000058a0| 29 20 7b 0d 09 09 09 09 | 09 6f 63 74 72 65 65 4e |) {.....|.octreeN|
|000058b0| 6f 64 65 20 2a 70 61 72 | 65 6e 74 20 3d 20 26 74 |ode *par|ent = &t|
|000058c0| 72 65 65 2d 3e 6e 6f 64 | 65 42 61 73 65 5b 6e 6f |ree->nod|eBase[no|
|000058d0| 64 65 2d 3e 70 61 72 65 | 6e 74 5d 3b 0d 09 09 09 |de->pare|nt];....|
|000058e0| 09 09 73 68 6f 72 74 20 | 63 6f 75 6e 74 65 72 20 |..short |counter |
|000058f0| 3d 20 38 3b 0d 09 09 09 | 09 09 77 68 69 6c 65 28 |= 8;....|..while(|
|00005900| 20 2d 2d 63 6f 75 6e 74 | 65 72 20 3e 3d 20 30 20 | --count|er >= 0 |
|00005910| 29 20 7b 0d 09 09 09 09 | 09 09 69 66 28 20 70 61 |) {.....|..if( pa|
|00005920| 72 65 6e 74 2d 3e 6c 65 | 61 66 5b 63 6f 75 6e 74 |rent->le|af[count|
|00005930| 65 72 5d 20 3d 3d 20 70 | 61 72 65 6e 74 49 6e 64 |er] == p|arentInd|
|00005940| 65 78 20 29 20 7b 0d 09 | 09 09 09 09 09 09 73 68 |ex ) {..|......sh|
|00005950| 6f 72 74 20 63 6f 6c 6f | 72 49 6e 64 65 78 3b 0d |ort colo|rIndex;.|
|00005960| 0d 09 09 09 09 09 09 2f | 2a 20 6f 72 70 68 61 6e |......./|* orphan|
|00005970| 20 74 68 65 20 63 6f 6c | 6f 72 20 66 72 6f 6d 20 | the col|or from |
|00005980| 69 74 73 20 70 61 72 65 | 6e 74 20 2a 2f 0d 0d 09 |its pare|nt */...|
|00005990| 09 09 09 09 09 09 7b 09 | 6f 63 74 72 65 65 4e 6f |......{.|octreeNo|
|000059a0| 64 65 20 2a 63 6f 6c 6f | 72 50 61 72 65 6e 74 20 |de *colo|rParent |
|000059b0| 3d 20 26 74 72 65 65 2d | 3e 6e 6f 64 65 42 61 73 |= &tree-|>nodeBas|
|000059c0| 65 5b 63 6f 6c 6f 72 2d | 3e 70 61 72 65 6e 74 5d |e[color-|>parent]|
|000059d0| 3b 0d 09 09 09 09 09 09 | 09 09 73 68 6f 72 74 20 |;.......|..short |
|000059e0| 63 6f 75 6e 74 65 72 20 | 3d 20 38 3b 0d 09 09 09 |counter |= 8;....|
|000059f0| 09 09 09 09 09 63 6f 6c | 6f 72 49 6e 64 65 78 20 |.....col|orIndex |
|00005a00| 3d 20 7e 28 63 6f 6c 6f | 72 20 2d 20 26 74 72 65 |= ~(colo|r - &tre|
|00005a10| 65 2d 3e 63 6f 6c 6f 72 | 42 61 73 65 5b 30 5d 29 |e->color|Base[0])|
|00005a20| 3b 0d 09 09 09 09 09 09 | 09 09 77 68 69 6c 65 28 |;.......|..while(|
|00005a30| 20 2d 2d 63 6f 75 6e 74 | 65 72 20 3e 3d 20 30 20 | --count|er >= 0 |
|00005a40| 29 20 7b 0d 09 09 09 09 | 09 09 09 09 09 69 66 28 |) {.....|.....if(|
|00005a50| 20 63 6f 6c 6f 72 50 61 | 72 65 6e 74 2d 3e 6c 65 | colorPa|rent->le|
|00005a60| 61 66 5b 63 6f 75 6e 74 | 65 72 5d 20 3d 3d 20 63 |af[count|er] == c|
|00005a70| 6f 6c 6f 72 49 6e 64 65 | 78 20 29 20 7b 0d 09 09 |olorInde|x ) {...|
|00005a80| 09 09 09 09 09 09 09 09 | 63 6f 6c 6f 72 50 61 72 |........|colorPar|
|00005a90| 65 6e 74 2d 3e 6c 65 61 | 66 5b 63 6f 75 6e 74 65 |ent->lea|f[counte|
|00005aa0| 72 5d 20 3d 20 65 6d 70 | 74 79 4e 6f 64 65 3b 0d |r] = emp|tyNode;.|
|00005ab0| 09 09 09 09 09 09 09 09 | 09 09 67 6f 74 6f 20 6f |........|..goto o|
|00005ac0| 72 70 68 61 6e 43 6f 6c | 6f 72 3b 0d 09 09 09 09 |rphanCol|or;.....|
|00005ad0| 09 09 09 09 09 7d 0d 09 | 09 09 09 09 09 09 09 7d |.....}..|.......}|
|00005ae0| 0d 09 09 09 09 09 09 09 | 09 49 66 44 65 62 75 67 |........|.IfDebug|
|00005af0| 28 31 2c 20 22 5c 70 63 | 6f 75 6c 64 6e 74 20 66 |(1, "\pc|ouldnt f|
|00005b00| 69 6e 64 20 63 6f 6c 6f | 72 20 69 6e 20 70 61 72 |ind colo|r in par|
|00005b10| 65 6e 74 22 29 3b 0d 09 | 09 09 09 09 09 09 7d 0d |ent");..|......}.|
|00005b20| 6f 72 70 68 61 6e 43 6f | 6c 6f 72 3a 09 09 09 09 |orphanCo|lor:....|
|00005b30| 09 63 6f 6c 6f 72 2d 3e | 70 61 72 65 6e 74 20 3d |.color->|parent =|
|00005b40| 20 65 6d 70 74 79 4e 6f | 64 65 3b 0d 09 09 09 09 | emptyNo|de;.....|
|00005b50| 09 09 09 56 61 6c 69 64 | 61 74 65 54 72 65 65 28 |...Valid|ateTree(|
|00005b60| 74 72 65 65 29 3b 0d 0d | 09 09 09 09 09 09 09 63 |tree);..|.......c|
|00005b70| 6f 6c 6f 72 20 3d 20 52 | 65 64 75 63 65 4e 6f 64 |olor = R|educeNod|
|00005b80| 65 28 74 72 65 65 2c 20 | 6e 6f 64 65 2c 20 63 6f |e(tree, |node, co|
|00005b90| 6c 6f 72 29 3b 0d 09 09 | 09 09 09 09 09 56 61 6c |lor);...|.....Val|
|00005ba0| 69 64 61 74 65 54 72 65 | 65 28 74 72 65 65 29 3b |idateTre|e(tree);|
|00005bb0| 0d 09 09 09 09 09 09 09 | 63 6f 6c 6f 72 49 6e 64 |........|colorInd|
|00005bc0| 65 78 20 3d 20 63 6f 6c | 6f 72 20 2d 20 26 74 72 |ex = col|or - &tr|
|00005bd0| 65 65 2d 3e 63 6f 6c 6f | 72 42 61 73 65 5b 30 5d |ee->colo|rBase[0]|
|00005be0| 3b 0d 09 09 09 09 09 09 | 09 52 65 6d 6f 76 65 43 |;.......|.RemoveC|
|00005bf0| 6f 6c 6f 72 46 72 6f 6d | 4c 65 76 65 6c 28 74 72 |olorFrom|Level(tr|
|00005c00| 65 65 2c 20 63 6f 6c 6f | 72 49 6e 64 65 78 29 3b |ee, colo|rIndex);|
|00005c10| 0d 09 09 09 09 09 09 09 | 63 6f 6c 6f 72 2d 3e 6c |........|color->l|
|00005c20| 65 76 65 6c 20 3d 20 6c | 65 76 65 6c 20 2d 20 31 |evel = l|evel - 1|
|00005c30| 3b 0d 09 09 09 09 09 09 | 09 63 6f 6c 6f 72 2d 3e |;.......|.color->|
|00005c40| 70 61 72 65 6e 74 20 3d | 20 70 61 72 65 6e 74 20 |parent =| parent |
|00005c50| 2d 20 26 74 72 65 65 2d | 3e 6e 6f 64 65 42 61 73 |- &tree-|>nodeBas|
|00005c60| 65 5b 30 5d 3b 0d 09 09 | 09 09 09 09 09 70 61 72 |e[0];...|.....par|
|00005c70| 65 6e 74 2d 3e 6c 65 61 | 66 5b 63 6f 75 6e 74 65 |ent->lea|f[counte|
|00005c80| 72 5d 20 3d 20 7e 63 6f | 6c 6f 72 49 6e 64 65 78 |r] = ~co|lorIndex|
|00005c90| 3b 0d 09 09 09 09 09 09 | 09 63 6f 6c 6f 72 2d 3e |;.......|.color->|
|00005ca0| 6e 65 78 74 20 3d 20 74 | 72 65 65 2d 3e 63 6f 6c |next = t|ree->col|
|00005cb0| 6f 72 4c 69 73 74 5b 6c | 65 76 65 6c 20 2d 20 31 |orList[l|evel - 1|
|00005cc0| 5d 3b 0d 09 09 09 09 09 | 09 09 74 72 65 65 2d 3e |];......|..tree->|
|00005cd0| 63 6f 6c 6f 72 4c 69 73 | 74 5b 6c 65 76 65 6c 20 |colorLis|t[level |
|00005ce0| 2d 20 31 5d 20 3d 20 63 | 6f 6c 6f 72 49 6e 64 65 |- 1] = c|olorInde|
|00005cf0| 78 3b 0d 09 09 09 09 09 | 09 09 52 65 6d 6f 76 65 |x;......|..Remove|
|00005d00| 4f 62 73 6f 6c 65 74 65 | 4e 6f 64 65 73 28 74 72 |Obsolete|Nodes(tr|
|00005d10| 65 65 29 3b 0d 09 09 09 | 09 09 09 09 72 65 74 75 |ee);....|....retu|
|00005d20| 72 6e 3b 0d 09 09 09 09 | 09 09 7d 0d 09 09 09 09 |rn;.....|..}.....|
|00005d30| 09 7d 0d 09 09 09 09 09 | 49 66 44 65 62 75 67 28 |.}......|IfDebug(|
|00005d40| 31 2c 20 22 5c 70 63 61 | 6e 74 20 66 69 6e 64 20 |1, "\pca|nt find |
|00005d50| 6e 6f 64 65 20 69 6e 20 | 70 61 72 65 6e 74 22 29 |node in |parent")|
|00005d60| 3b 0d 09 09 09 09 7d 0d | 09 09 09 09 69 6e 64 65 |;.....}.|....inde|
|00005d70| 78 20 3d 20 63 6f 6c 6f | 72 2d 3e 6e 65 78 74 3b |x = colo|r->next;|
|00005d80| 0d 09 09 09 7d 0d 09 09 | 09 2b 2b 69 6e 6e 65 72 |....}...|.++inner|
|00005d90| 4c 65 76 65 6c 3b 0d 09 | 09 7d 0d 0d 09 09 2d 2d |Level;..|.}....--|
|00005da0| 6c 65 76 65 6c 3b 0d 09 | 7d 0d 0d 09 49 66 44 65 |level;..|}...IfDe|
|00005db0| 62 75 67 28 31 2c 20 22 | 5c 70 75 6e 61 62 6c 65 |bug(1, "|\punable|
|00005dc0| 20 74 6f 20 72 65 64 75 | 63 65 20 74 68 65 20 6f | to redu|ce the o|
|00005dd0| 63 74 72 65 65 22 29 3b | 0d 7d 0d 0d 0d 70 61 73 |ctree");|.}...pas|
|00005de0| 63 61 6c 20 73 68 6f 72 | 74 20 49 6e 69 74 4f 63 |cal shor|t InitOc|
|00005df0| 74 72 65 65 28 73 68 6f | 72 74 20 63 6f 6c 6f 72 |tree(sho|rt color|
|00005e00| 73 52 65 71 75 65 73 74 | 65 64 2c 20 6c 6f 6e 67 |sRequest|ed, long|
|00005e10| 20 2a 64 61 74 61 48 61 | 6e 64 6c 65 50 74 72 2c | *dataHa|ndlePtr,|
|00005e20| 20 73 68 6f 72 74 20 2a | 62 61 6e 6b 54 79 70 65 | short *|bankType|
|00005e30| 29 0d 7b 0d 09 6f 63 74 | 72 65 65 20 2a 74 72 65 |).{..oct|ree *tre|
|00005e40| 65 3b 0d 09 6f 63 74 72 | 65 65 4e 6f 64 65 20 2a |e;..octr|eeNode *|
|00005e50| 6e 6f 64 65 3b 0d 09 48 | 61 6e 64 6c 65 20 64 61 |node;..H|andle da|
|00005e60| 74 61 48 61 6e 64 6c 65 | 2c 20 74 65 6d 70 48 61 |taHandle|, tempHa|
|00005e70| 6e 64 6c 65 3b 0d 09 73 | 68 6f 72 74 20 63 6f 75 |ndle;..s|hort cou|
|00005e80| 6e 74 65 72 3b 0d 0d 09 | 69 66 28 20 63 6f 6c 6f |nter;...|if( colo|
|00005e90| 72 73 52 65 71 75 65 73 | 74 65 64 20 3c 20 34 20 |rsReques|ted < 4 |
|00005ea0| 7c 7c 20 63 6f 6c 6f 72 | 73 52 65 71 75 65 73 74 ||| color|sRequest|
|00005eb0| 65 64 20 3e 20 32 35 36 | 20 29 0d 09 09 72 65 74 |ed > 256| )...ret|
|00005ec0| 75 72 6e 20 63 6f 6c 6f | 72 73 52 65 71 75 65 73 |urn colo|rsReques|
|00005ed0| 74 65 64 45 72 72 3b 0d | 0d 09 64 61 74 61 48 61 |tedErr;.|..dataHa|
|00005ee0| 6e 64 6c 65 20 3d 20 4e | 65 77 48 61 6e 64 6c 65 |ndle = N|ewHandle|
|00005ef0| 43 6c 65 61 72 28 73 69 | 7a 65 6f 66 28 6f 63 74 |Clear(si|zeof(oct|
|00005f00| 72 65 65 29 29 3b 0d 09 | 69 66 28 20 64 61 74 61 |ree));..|if( data|
|00005f10| 48 61 6e 64 6c 65 20 3d | 3d 20 6e 69 6c 20 29 0d |Handle =|= nil ).|
|00005f20| 09 09 72 65 74 75 72 6e | 20 6d 65 6d 46 75 6c 6c |..return| memFull|
|00005f30| 45 72 72 3b 0d 0d 09 48 | 4c 6f 63 6b 28 64 61 74 |Err;...H|Lock(dat|
|00005f40| 61 48 61 6e 64 6c 65 29 | 3b 0d 09 74 72 65 65 20 |aHandle)|;..tree |
|00005f50| 3d 20 2a 28 6f 63 74 72 | 65 65 20 2a 2a 29 64 61 |= *(octr|ee **)da|
|00005f60| 74 61 48 61 6e 64 6c 65 | 3b 0d 09 63 6f 75 6e 74 |taHandle|;..count|
|00005f70| 65 72 20 3d 20 6d 61 78 | 69 6d 75 6d 4c 65 76 65 |er = max|imumLeve|
|00005f80| 6c 20 2b 20 31 3b 0d 09 | 77 68 69 6c 65 28 20 2d |l + 1;..|while( -|
|00005f90| 2d 63 6f 75 6e 74 65 72 | 20 3e 3d 20 30 20 29 0d |-counter| >= 0 ).|
|00005fa0| 09 09 74 72 65 65 2d 3e | 63 6f 6c 6f 72 4c 69 73 |..tree->|colorLis|
|00005fb0| 74 5b 63 6f 75 6e 74 65 | 72 5d 20 3d 20 65 6d 70 |t[counte|r] = emp|
|00005fc0| 74 79 4e 6f 64 65 3b 0d | 0d 09 74 72 65 65 2d 3e |tyNode;.|..tree->|
|00005fd0| 6d 61 78 69 6d 75 6d 4e | 6f 64 65 73 20 3d 20 31 |maximumN|odes = 1|
|00005fe0| 20 2b 20 38 20 2b 20 36 | 34 3b 09 2f 2a 20 66 6f | + 8 + 6|4;./* fo|
|00005ff0| 72 20 6c 65 76 65 6c 20 | 30 2c 20 31 2c 20 61 6e |r level |0, 1, an|
|00006000| 64 20 32 2e 20 49 66 20 | 74 68 65 20 6d 61 78 69 |d 2. If |the maxi|
|00006010| 6d 75 6d 4c 65 76 65 6c | 20 69 73 20 74 68 72 65 |mumLevel| is thre|
|00006020| 65 2c 20 74 68 65 6e 20 | 74 68 65 20 6e 65 78 74 |e, then |the next|
|00006030| 20 6c 65 76 65 6c 20 77 | 69 6c 6c 20 62 65 20 63 | level w|ill be c|
|00006040| 6f 6c 6f 72 73 20 2a 2f | 0d 09 69 66 28 20 6d 61 |olors */|..if( ma|
|00006050| 78 69 6d 75 6d 4c 65 76 | 65 6c 20 3e 20 33 20 29 |ximumLev|el > 3 )|
|00006060| 0d 09 09 74 72 65 65 2d | 3e 6d 61 78 69 6d 75 6d |...tree-|>maximum|
|00006070| 4e 6f 64 65 73 20 2b 3d | 20 28 63 6f 6c 6f 72 73 |Nodes +=| (colors|
|00006080| 52 65 71 75 65 73 74 65 | 64 20 2b 20 31 29 20 2a |Requeste|d + 1) *|
|00006090| 20 28 6d 61 78 69 6d 75 | 6d 4c 65 76 65 6c 20 2d | (maximu|mLevel -|
|000060a0| 20 33 29 3b 0d 09 74 65 | 6d 70 48 61 6e 64 6c 65 | 3);..te|mpHandle|
|000060b0| 20 3d 20 4e 65 77 48 61 | 6e 64 6c 65 28 74 72 65 | = NewHa|ndle(tre|
|000060c0| 65 2d 3e 6d 61 78 69 6d | 75 6d 4e 6f 64 65 73 20 |e->maxim|umNodes |
|000060d0| 2a 20 73 69 7a 65 6f 66 | 28 6f 63 74 72 65 65 4e |* sizeof|(octreeN|
|000060e0| 6f 64 65 29 29 3b 0d 09 | 48 4c 6f 63 6b 28 74 65 |ode));..|HLock(te|
|000060f0| 6d 70 48 61 6e 64 6c 65 | 29 3b 0d 09 74 72 65 65 |mpHandle|);..tree|
|00006100| 2d 3e 6e 6f 64 65 42 61 | 73 65 20 3d 20 2a 28 6f |->nodeBa|se = *(o|
|00006110| 63 74 72 65 65 4e 6f 64 | 65 20 2a 2a 29 74 65 6d |ctreeNod|e **)tem|
|00006120| 70 48 61 6e 64 6c 65 3b | 0d 09 74 72 65 65 2d 3e |pHandle;|..tree->|
|00006130| 6e 6f 64 65 73 20 3d 20 | 31 3b 0d 09 6e 6f 64 65 |nodes = |1;..node|
|00006140| 20 3d 20 26 74 72 65 65 | 2d 3e 6e 6f 64 65 42 61 | = &tree|->nodeBa|
|00006150| 73 65 5b 30 5d 3b 0d 09 | 6e 6f 64 65 2d 3e 63 68 |se[0];..|node->ch|
|00006160| 69 6c 64 72 65 6e 20 3d | 20 30 3b 0d 09 6e 6f 64 |ildren =| 0;..nod|
|00006170| 65 2d 3e 70 61 72 65 6e | 74 20 3d 20 65 6d 70 74 |e->paren|t = empt|
|00006180| 79 4e 6f 64 65 3b 0d 09 | 63 6f 75 6e 74 65 72 20 |yNode;..|counter |
|00006190| 3d 20 38 3b 0d 09 77 68 | 69 6c 65 28 20 2d 2d 63 |= 8;..wh|ile( --c|
|000061a0| 6f 75 6e 74 65 72 20 3e | 3d 20 30 20 29 0d 09 09 |ounter >|= 0 )...|
|000061b0| 6e 6f 64 65 2d 3e 6c 65 | 61 66 5b 63 6f 75 6e 74 |node->le|af[count|
|000061c0| 65 72 5d 20 3d 20 65 6d | 70 74 79 4e 6f 64 65 3b |er] = em|ptyNode;|
|000061d0| 0d 0d 09 74 72 65 65 2d | 3e 6d 61 78 69 6d 75 6d |...tree-|>maximum|
|000061e0| 43 6f 6c 6f 72 73 20 3d | 20 63 6f 6c 6f 72 73 52 |Colors =| colorsR|
|000061f0| 65 71 75 65 73 74 65 64 | 20 2b 20 31 3b 0d 09 74 |equested| + 1;..t|
|00006200| 65 6d 70 48 61 6e 64 6c | 65 20 3d 20 4e 65 77 48 |empHandl|e = NewH|
|00006210| 61 6e 64 6c 65 28 74 72 | 65 65 2d 3e 6d 61 78 69 |andle(tr|ee->maxi|
|00006220| 6d 75 6d 43 6f 6c 6f 72 | 73 20 2a 20 73 69 7a 65 |mumColor|s * size|
|00006230| 6f 66 28 6f 63 74 72 65 | 65 43 6f 6c 6f 72 29 29 |of(octre|eColor))|
|00006240| 3b 0d 09 48 4c 6f 63 6b | 28 74 65 6d 70 48 61 6e |;..HLock|(tempHan|
|00006250| 64 6c 65 29 3b 0d 09 74 | 72 65 65 2d 3e 63 6f 6c |dle);..t|ree->col|
|00006260| 6f 72 42 61 73 65 20 3d | 20 2a 28 6f 63 74 72 65 |orBase =| *(octre|
|00006270| 65 43 6f 6c 6f 72 20 2a | 2a 29 74 65 6d 70 48 61 |eColor *|*)tempHa|
|00006280| 6e 64 6c 65 3b 0d 0d 09 | 48 55 6e 6c 6f 63 6b 28 |ndle;...|HUnlock(|
|00006290| 64 61 74 61 48 61 6e 64 | 6c 65 29 3b 0d 0d 09 2a |dataHand|le);...*|
|000062a0| 64 61 74 61 48 61 6e 64 | 6c 65 50 74 72 20 3d 20 |dataHand|lePtr = |
|000062b0| 28 6c 6f 6e 67 29 64 61 | 74 61 48 61 6e 64 6c 65 |(long)da|taHandle|
|000062c0| 3b 0d 09 2a 62 61 6e 6b | 54 79 70 65 20 3d 20 43 |;..*bank|Type = C|
|000062d0| 6f 6c 6f 72 42 61 6e 6b | 49 73 43 75 73 74 6f 6d |olorBank|IsCustom|
|000062e0| 3b 0d 09 72 65 74 75 72 | 6e 20 6e 6f 45 72 72 3b |;..retur|n noErr;|
|000062f0| 0d 7d 0d 0d 0d 70 61 73 | 63 61 6c 20 73 68 6f 72 |.}...pas|cal shor|
|00006300| 74 20 4b 69 6c 6c 4f 63 | 74 72 65 65 28 6c 6f 6e |t KillOc|tree(lon|
|00006310| 67 20 64 61 74 61 48 61 | 6e 64 6c 65 29 0d 7b 0d |g dataHa|ndle).{.|
|00006320| 09 6f 63 74 72 65 65 20 | 2a 74 72 65 65 20 3d 20 |.octree |*tree = |
|00006330| 2a 28 6f 63 74 72 65 65 | 20 2a 2a 29 64 61 74 61 |*(octree| **)data|
|00006340| 48 61 6e 64 6c 65 3b 0d | 0d 09 44 69 73 70 6f 73 |Handle;.|..Dispos|
|00006350| 65 48 61 6e 64 6c 65 28 | 52 65 63 6f 76 65 72 48 |eHandle(|RecoverH|
|00006360| 61 6e 64 6c 65 28 74 72 | 65 65 2d 3e 63 6f 6c 6f |andle(tr|ee->colo|
|00006370| 72 42 61 73 65 29 29 3b | 0d 09 44 69 73 70 6f 73 |rBase));|..Dispos|
|00006380| 65 48 61 6e 64 6c 65 28 | 52 65 63 6f 76 65 72 48 |eHandle(|RecoverH|
|00006390| 61 6e 64 6c 65 28 74 72 | 65 65 2d 3e 6e 6f 64 65 |andle(tr|ee->node|
|000063a0| 42 61 73 65 29 29 3b 0d | 09 44 69 73 70 6f 73 65 |Base));.|.Dispose|
|000063b0| 48 61 6e 64 6c 65 28 28 | 48 61 6e 64 6c 65 29 64 |Handle((|Handle)d|
|000063c0| 61 74 61 48 61 6e 64 6c | 65 29 3b 0d 09 72 65 74 |ataHandl|e);..ret|
|000063d0| 75 72 6e 20 6e 6f 45 72 | 72 3b 0d 7d 0d 0d 0d 70 |urn noEr|r;.}...p|
|000063e0| 61 73 63 61 6c 20 73 68 | 6f 72 74 20 52 65 63 6f |ascal sh|ort Reco|
|000063f0| 72 64 4f 63 74 72 65 65 | 43 6f 6c 6f 72 73 28 6c |rdOctree|Colors(l|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.